Skip to content
Advertisement

error on MySQL when i add month to the query [closed]

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?

Advertisement

Answer

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
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement