jawbreaker Posted April 19, 2006 Share Posted April 19, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/7876-date-adding-months/ Share on other sites More sharing options...
ober Posted April 19, 2006 Share Posted April 19, 2006 Use the mktime() function. Quote Link to comment https://forums.phpfreaks.com/topic/7876-date-adding-months/#findComment-28712 Share on other sites More sharing options...
jawbreaker Posted April 19, 2006 Author Share Posted April 19, 2006 How would I use the mktime() function using two variables? $Date = 2006-01-01$MonthsToAdd = 6 Quote Link to comment https://forums.phpfreaks.com/topic/7876-date-adding-months/#findComment-28729 Share on other sites More sharing options...
arifsor Posted April 19, 2006 Share Posted April 19, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/7876-date-adding-months/#findComment-28731 Share on other sites More sharing options...
Barand Posted April 19, 2006 Share Posted April 19, 2006 ... or[code]$Date = '2006-01-01';$MonthsToAdd = 6;echo date ('Y-m-d', strtotime("+$MonthsToAdd months $Date"));[/code] Quote Link to comment https://forums.phpfreaks.com/topic/7876-date-adding-months/#findComment-28738 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.