Jump to content


Photo

Date - Adding months


  • Please log in to reply
4 replies to this topic

#1 jawbreaker

jawbreaker
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 19 April 2006 - 07:09 PM

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?

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 19 April 2006 - 07:11 PM

Use the mktime() function.

Info: PHP Manual


#3 jawbreaker

jawbreaker
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 19 April 2006 - 07:45 PM

How would I use the mktime() function using two variables?

$Date = 2006-01-01
$MonthsToAdd = 6



#4 arifsor

arifsor
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts
  • LocationPakistan

Posted 19 April 2006 - 07:50 PM

[!--quoteo(post=366577:date=Apr 19 2006, 02:45 PM:name=jawbreaker)--][div class=\'quotetop\']QUOTE(jawbreaker @ Apr 19 2006, 02:45 PM) View Post[/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.


---------------------------
Power Demand Respect
Arif Sorathia

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 19 April 2006 - 08:07 PM

... or

$Date = '2006-01-01';
$MonthsToAdd = 6;

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

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users