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>';
}
?>
Try using a unix timestamp and adding 86400 each time. That's gotta be faster than calling strtotime()
. You can lookup timestamp conversions online.
<?php
$check_date = 1267228800; // '2010-02-27';
$end_date = 1269388800; // '2010-03-24';
while($check_date != $end_date){
$check_date += 86400;
echo date("Ymd", $check_date) . '<br>';
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With