Well, I need get two values that represents the distance between two full dates-only (no hour/time)… On MySQL we have PERIOD_DIFF that get the diff between two dates (only month and year), but I need to include the day too.
I have two dates like:
2011-12-05and2012-01-10. After2012-01-05I have 1 full month, more 5 days.2012-01-01and2012-03-01. I have 2 months and 0 day.2012-02-29and2012-03-28¹. I have 0 month and 28 days. More: for 1 month, I need2012-03-29.2013-01-29and2013-02-28². I have 0 month and 30 days. More: for 1 month, I need2013-03-01, because2013-02-29not exists.2013-03-31and2013-04-30. Fix: really I have 0 month and 30 days. More: for 1 month, I need2013-05-01, because2013-04-31not exists.
¹ 2012 is a leap year / bissexto;
² 2013 is not;
I don’t know what I need do exactly to solve that.
Set some variable for total difference in months to 0.
Use
DATEDIFFto get the total difference in days between your start and end date.For each month between your start and end month (if there are any months in between), use
LAST_DAYandDATEDIFFto calculate the number of days for that month.Subtract the number of days for that month from the total difference in days, and add 1 to the total difference in months.