-1

I have a dataset including a endDate and a startDate:

endDate startDate
2021-02-01 2021-06-30

now I try datediff(endDate, startDate) and I get: 149

when I try datediff(month,endDate, startDate) I get error

1582 incorrect parameter

what is wrong?

Deepak Rai
  • 2,163
  • 3
  • 21
  • 36
Albert
  • 13
  • 2
  • 2
    Hint: `datediff()` in MySQL takes two arguments, as your first example shows,. – Gordon Linoff Jan 29 '21 at 22:01
  • but docs say I can do DATEDIFF ( datepart , startdate , enddate ) and datepart could be month or year, so it takes 3 arguments,.... – Albert Jan 29 '21 at 22:10
  • 1
    The documentation is [here](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_datediff) it doesn't show that. Are you sure you're reading MySQL documentation? – Barmar Jan 29 '21 at 22:19
  • 1
    [`timestampdiff()`](https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_timestampdiff) allows you to specify the units. – Barmar Jan 29 '21 at 22:19
  • 3
    You're reading the SQL-Server documentation, not MySQL. https://learn.microsoft.com/en-us/sql/t-sql/functions/datediff-transact-sql?view=sql-server-ver15 – Barmar Jan 29 '21 at 22:20
  • ok wrong docs :) – Albert Jan 29 '21 at 22:23
  • Why is your start date after the end date? – Barmar Jan 29 '21 at 22:23
  • This is answered in the as part of this question https://stackoverflow.com/questions/4759248/difference-between-two-dates-in-mysql – roshaga Jan 29 '21 at 22:29

1 Answers1

0

You're trying to use the syntax from SQL-Server, it doesn't work with MySQL. In MySQL the function that allows you to specify the time units of the result is TIMESTAMPDIFF

SELECT TIMESTAMPDIFF(MONTH, startDate, endDate)
FROM tablename
Barmar
  • 741,623
  • 53
  • 500
  • 612