Page 1 of 1

want to add 6 months in the date coming from database

Posted: Mon Dec 10, 2007 7:12 am
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

Posted: Mon Dec 10, 2007 8:18 am
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.

Posted: Mon Dec 10, 2007 9:23 am
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

Posted: Tue Dec 11, 2007 1:51 am
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