Page 1 of 1

adding a week to a mysql retrieved date

Posted: Wed Sep 20, 2006 6:49 am
by andym01480
Got a database that handles a weekly rota, so each row contains a date in the form yyyy-mm-dd.

I want to add another years worth of dates automatically.

I can grab the last date in the the table

Code: Select all

$query="SELECT date from sundayrota order by date desc";
$result=mysql_query($query);
$lastdate=mysql_fetch_assoc($result);
So $lastdate[date] contains 2006-12-31

What do I do to make it in a form that I can iterate adding 7 days to it 52 times and inserting it back in!

Can you help please

Posted: Wed Sep 20, 2006 6:57 am
by volka
If you stick with mysql you can let it calc the date

Code: Select all

SELECT
	date, date + Interval 1 year as future
FROM
	sundayrota
ORDER BY
	date desc
if you want php to do it you can use strtotime

Code: Select all

<?php
$future = strtotime('2006-12-31 + 1 year');
echo date('Y-m-d', $future);
?>
see http://dev.mysql.com/doc/refman/5.0/en/ ... tions.html and http://de2.php.net/strtotime