Calculation of the last day of the leap month in MySQL

Source: Internet
Author: User
Tags diff

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.