Hi.
I have 2 dates, the beginning and end date of a week, in format yyyy-mm-dd.
I need to register in a mysql table a row for each day of that week and I can't seem to figure out how to do it.
Can anybody help me?
Thanks in advance!!!
| SitePoint Sponsor |
Hi.
I have 2 dates, the beginning and end date of a week, in format yyyy-mm-dd.
I need to register in a mysql table a row for each day of that week and I can't seem to figure out how to do it.
Can anybody help me?
Thanks in advance!!!




PHP Code:<?php
$monday = '2009-08-03';
$monday = strtotime($monday); // convert to timestamp
$week = array();
for ($i = 0; $i < 7; $i++) {
$timestamp = mktime(0, 0, 0, date('m', $monday), date('d', $monday) + $i, date('Y', $monday));
$key = date('D', $timestamp);
$value = date('Y-m-d', $timestamp);
$week[$key] = $value;
}
echo '<pre>';
var_dump($week);
echo '</pre>';
// now you can loop through $week with foreach and build INSERT query
// then execute it to insert all rows to the table at once
You could also do
Code:insert into mytable (thedate) values ('2009-05-09' + INTERVAL 3 DAY)
Bookmarks