Search code examples
mysqldatediff

Finding the DATEDIFF between two columns and creating its own column


Trying to find the DATEDIFF between two dates and display it as it's own column. Here are my current columns: currentcolumns

And here is what I need: needed

Here is the code I have been running with error:

SELECT orderNumber, DATEDIFF(day,orderDate,shippedDate) AS day FROM datenumtest;

The error I get says: #1582 - Incorrect parameter count in the call to native function 'DATEDIFF'

I've looked at a ton of sites now and can't seem to see what the issue is. Ideas?


Solution

  • MySQL's DATEDIFF function just takes two parameters:

    SELECT orderNumber, DATEDIFF(shippedDate, orderDate) AS day
    FROM datenumtest;
    

    Note the order of the date parameters used, which would return some positive number of days assuming that the shipping date be greater than the order date.