I saw this code on a forum:
$begin = new DateTime( $start_date );
$end = new DateTime(date("Y-m-d",strtotime("+1 day", strtotime($end_date))));
while($begin < $end) {
$period[] = $begin->format('Y-m-d');
$begin->modify('+1 day');
}
I want to do exactly what the OP was asking i.e. create a date interval of 1 day without using DateInterval class as I am not using PHP 5.3 (I’m using 5.2)
However when I try to use the $period array I get an error:
Undefined variable: period
This is my code:
$start = new DateTime("09-09-2011");
$end = new DateTime("24-09-2011");
while($start < $end) {
$period[] = $start->format('Y-m-d');
$start->modify('+1 day');
}
print_r($period) //error - undefined variable
Why does it not work – is it to do with putting a datetime object in a while loop?
so define it easily
however, this will never go to that while loop = this code is not useful