How to add number of days in a date in mySQL?

A client was running a membership driven website for some time now. He had been offering free membership and no membership expiry up till now. However, some where along the way he was bit by the commercial bug 🙂 and he decided on ending free membership for all members. He wanted his members to pay for the membership (6 months). So he asked me to make the necessary adjustments in the code to support his new business requirement.

I made the necessary adjustments in the code and database structure. After making the changes I had to update the new field I had added for the expiry date in the membership table. I could have done it by writing a script and updating all the records but I said hey lets do it in mySQL.

I wrote the following query

update members set date_expiry = adddate(date_created,180);

and ran it in mySQL and it updated all the records.

Hope the above helped.

Leave a Comment