A strange problem arises in the calculation of the date:
If the current date is February 29 of a leap year, then for the current date + N years, then the corresponding date becomes February 28. But this does not accord with our common sense, according to common sense, when only 28 days, time should be postponed one day, become March 1.
For example, the following SQL band is used to calculate this year's birthday date:
SelectName,birthday,now (), Date_add (Birthday1, INTERVALIF( Day(birthday)= in && Day(Birthday1)= -,1,0) Day) asBirthday2 from( SelectName,birthday,date_add (Birthday,interval diff Year) asBirthday1 from( SelectName,birthday, ( Year(Now ())- Year(birthday)) asdiff from User ))
One of the first loops is the year in which to calculate the difference between the current date and the date of birth.
The second cycle, a preliminary calculation of the birthday date for several years.
Third cycle, further amending the date of birth.
Calculation of the last day of the leap month in MySQL