I am using the MySQL TIMESTAMPDIFF()
function to calculate the difference in months between two dates, but there is a problem with overflow.
Say I have a date, and I use MySQL to calculate the same date 1 month later:
select DATE_ADD('2018-10-31', INTERVAL 1 MONTH)
returns 2018-11-30
So, now I have two dates, 2018-10-31 and 2018-11-30.
Now I would like to calculate the interval in months between those dates, but
select TIMESTAMPDIFF(MONTH, '2018-10-31', '2018-11-30')
returns 0
, because of the number of days in November that DATE_ADD() adjusts for.
So, given two dates, which are calculated as above with DATE_ADD() and an interval of n months, is it possible to use either TIMESTAMPDIFF() or a different function to calculate n?