Jump to content

Archived

This topic is now archived and is closed to further replies.

jawbreaker

Date - Adding months

Recommended Posts

I have a date stored in a MySQL table that I need to add a number of months to stored in another MySQL table. The date is stored in the date format in one of my tables: YYYY-MM-DD. How do I add the month to this date using PHP?

Share this post


Link to post
Share on other sites
Use the mktime() function.

Share this post


Link to post
Share on other sites
[!--quoteo(post=366577:date=Apr 19 2006, 02:45 PM:name=jawbreaker)--][div class=\'quotetop\']QUOTE(jawbreaker @ Apr 19 2006, 02:45 PM) [snapback]366577[/snapback][/div][div class=\'quotemain\'][!--quotec--]
How would I use the mktime() function using two variables?

$Date = 2006-01-01
$MonthsToAdd = 6
[/quote]
instead of using php mktime. you can use ADD_MONTH function of mysql . i dont remember the proper function name but i have done it before.

Share this post


Link to post
Share on other sites
... or

[code]$Date = '2006-01-01';
$MonthsToAdd = 6;

echo date ('Y-m-d', strtotime("+$MonthsToAdd months $Date"));[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.