问题描述:

Why is

TIMESTAMPDIFF(MONTH, '2015-12-25', '2016-02-24')

giving me 1? I would expect 2016-01-25 to be 1.

My guess is that it is actually returning something like 1.999 months and it is being simply rounded down.

How can I work around this? Or is there another function to use.

I tried PERIOD_DIFF but it does not take into account days

PERIOD_DIFF(DATE_FORMAT('2016-02-24','%Y%m'),DATE_FORMAT('2015-12-25','%Y%m'))

网友答案:

According to the documentation, the unit for the result is an integer, in your case it will return the whole number of months between the two dates, which is one (as the second month is not yet completed).

相关阅读:
Top