Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the DATEDIFF between two columns and creating its own column [duplicate]

Tags:

mysql

datediff

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?

like image 271
Shawn Benson Avatar asked Sep 11 '25 14:09

Shawn Benson


1 Answers

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.

like image 153
Tim Biegeleisen Avatar answered Sep 13 '25 05:09

Tim Biegeleisen