I am trying to loop through dates with PHP. Currently my code gets stuck in a loop repeating 110307. I need the date format to be in yymmdd. Here is what I was trying to use:
<?php
$check_date = '100227';
$end_date = '100324';
while($check_date != $end_date){
$check_date = date("ymd", strtotime("+1 day", strtotime($check_date)));
echo $check_date . '<br>';
}
?>
strtotimeinterprets “100227” as the time 10:02:27 today, not 2010-02-27. So after the first step,$check_date(today) is “110307”. At all subsequent steps “110307” is again interpreted as a time today, giving$check_dateas “110307” again.A neat trick for iterating dates is to take advantage of mktime’s ability to normalize dates, something like this: