Page 1 of 1

Advancing a date()

Posted: Sat Aug 30, 2003 2:53 pm
by larrytech
Hi,
I have had a look around for an answer to this, and maybe I am searching for the wrong thing because I cannot find anything!

I have a date in a mysql database that is in the format 2003-01-29. This is then formatted on the actual page to 29 Jan 2003. I am wondering whether it is possible to easily add thirty days to any date, so that a date in the future is shown exactly thirty days ahead. I expect it should know about the number of days in the month and compensate for this.

Is there an easy was of doing this or would I be better to work it out each time myself?

Thanks a lot,
Lawrence

Posted: Sat Aug 30, 2003 5:56 pm
by volka
you might query it from mysql

Code: Select all

SELECT Now() + interval 30 day

Code: Select all

SELECT '2003-01-29' + interval 30 day

Code: Select all

SELECT <date field> + interval 30 day as future FROM <tablename>
or use mktime

Code: Select all

<?php
$date = getdate();
$future = mktime (0,0,1, $date['mon'], $date['mday']+30, $date['year']);
echo date("F j, Y, g:i a", $future);
?>

Code: Select all

<?php
$date = getdate(strtotime ('29 Jan 2003'));
$future = mktime (0,0,1, $date['mon'], $date['mday']+30, $date['year']);
echo date("F j, Y, g:i a", $future);
?>

Posted: Sun Aug 31, 2003 5:00 am
by larrytech
Thank you very much! That works just as wanted.
Lawrence