Antony D'Andrea
Antony D'Andrea

Reputation: 1004

TIMESTAMPDIFF giving unexpected result

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'))

Upvotes: 0

Views: 73

Answers (1)

Alex
Alex

Reputation: 21766

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).

Upvotes: 1

Related Questions