want to add 6 months in the date coming from database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
djdon11
Forum Commoner
Posts: 90
Joined: Wed Jun 20, 2007 5:03 pm

want to add 6 months in the date coming from database

Post by djdon11 »

Hi friends ..

well there is a date coming form my database now i want the date after the 6 months of the date coming from my database

can any body help me for this , there is any function which gives us the date by adding 6 months in the date coming from the database

for ex. if my date is 25/11/2007 than i need the date after the 6 month of 25/11/2007

please help me for this ..

thanks.

djdon11
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

using database functions or php ?

//PHP
1. you can use strtotime() and directly add +6 months. ...see man for examples.
2. If format of date you have is not recognizable by strtotime, build timestamp with mktime() and add 6 in there...then use date() to format appropriately.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

SELECT DATE_ADD(`your_date_field`, INTERVAL 6 MONTH)
http://dev.mysql.com/doc/refman/5.0/en/ ... n_date-add
worldofcarp
Forum Newbie
Posts: 2
Joined: Tue Nov 20, 2007 1:18 pm

Post by worldofcarp »

If you want to do it in php do it like this:

Code: Select all

strtotime('2007-11-25 +6 months');
You have to change the date format a little to that format to work, strtotime is a little finicky sometimes
Post Reply