I am writing this query in the mySQL DB. The table listing has two columns StartDate & EndDate. I want to return the Duration ie number of days between these two dates using DATEDIFF. My query is:
SELECT DATEDIFF(StartDate, EndDate) as 'Duration' FROM listing;
The table returns NULL in the Duration column.
And if I write,
SELECT DATEDIFF(day, StartDate, EndDate) as 'Duration' FROM listing;
returns
Error Code: 1582. Incorrect parameter count in the call to native function 'datediff' 0.000 sec
Any help will be appreciated.
The problem was that DATEDIFF() expects the dates to be in the format YYYYMMDD and the column inputs of StartDate and EndDate that I was giving was MMDDYYYY. I changed it to YYYYMMDD and it worked. So, the following expression with the dates in YYYYMMDD format works just fine.
SELECT DATEDIFF(StartDate, EndDate) as 'Duration' FROM listing;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With