Code:
<?php
$end_date ="September 1, 2011 18:00:00";
$end_date =date("YmdHis", strtotime("$end_date"));
$end_date1=$end_date;
$end_date=str_replace(" ","",$end_date);
$end_date=str_replace(":","",$end_date);
$end_date=str_replace("-","",$end_date);
$y1_end=substr($end_date,0,4);
$m1_end=substr($end_date,4,2);
$s1_end=substr($end_date,12,2);
$d1_end=substr($end_date,6,2);
$h1_end=substr($end_date,8,2);
$min1_end=substr($end_date,10,2);
$time_end="$m1_end/$d1_end/$y1_end $h1_end:$min1_end:$s1_end<br>";
$start_date="April 1, 2011 07:00:00";
$hour='0';
$day='0';
$counter='0';
while ($hour>=0){
if ($hour=='12') {$hour='0';$day++;}
$date=date("YmdHis", strtotime("$start_date + $hour hour + $day days"));
$hour++;$counter++;
$date=str_replace(" ","",$date);
$date=str_replace(":","",$date);
$date=str_replace("-","",$date);
$y1=substr($date,0,4);
$m1=substr($date,4,2);
$s1=substr($date,12,2);
$d1=substr($date,6,2);
$h1=substr($date,8,2);
$min1=substr($date,10,2);
$time="$m1/$d1/$y1 $h1:$min1:$s1<br>";
echo "$time";
if ($time_end=="$time") break;
if ($counter>5000) break;
}
?>
I wasn't sure what to use for the while statement while ($hour>=0){ so I just put it in an infinite loop to break when the desired date is reached.
EDIT: I'm not sure what dates you are working with, so I added the following line to act as a safe guard in case there is an error in the start or end date input so as to keep from generating a loop that goes on till the end of time, which in php is somewhere around January 19, 2038:
if ($counter>5000) break;
Bookmarks