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
Advancing a date()
Moderator: General Moderators
you might query it from mysqlor use mktime
Code: Select all
SELECT Now() + interval 30 dayCode: Select all
SELECT '2003-01-29' + interval 30 dayCode: Select all
SELECT <date field> + interval 30 day as future FROM <tablename>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);
?>