4

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?

Community
  • 1
  • 1
Shawn Benson
  • 137
  • 1
  • 7
  • `DATEDIFF` only has two parameters. `day` is not required as it always returns a value in days. See the [manual](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_datediff) – Nick Nov 03 '18 at 02:09

2 Answers2

3

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.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

DATEDIFF function in MySQL only supports two input parameters, whereas SQL Server variant of the function supports to derive days, month etc by passing in the additional parameter.

nanic
  • 76
  • 4