APD Toronto
asked on
Looping through Dates in PHP
Hi Experts,
How can I loop in between 2 dates?
For example, I have the following code:
However, this crashes my browser, ad I'm guessing because it goes through every millisecond? Which is what I don't want.
In comments I added my test data, so I am expecting the following output
Any help will be appreciated.
How can I loop in between 2 dates?
For example, I have the following code:
//Loop through DR
$date = new DateTime();
$date_from = new DateTime($from); //'2015-08-01'
$date_to = new DateTime($to); //'2015-08'14'
$date_optput = '';
$date_compare = '';
for ($date = $date_from; $date <= $date_to; $date++):
$date_optput = $date->format('D-M-y');
echo $date_optput . '<br>';
endfor;
However, this crashes my browser, ad I'm guessing because it goes through every millisecond? Which is what I don't want.
In comments I added my test data, so I am expecting the following output
1-Aug-15
2-Aug-15
3-Aug-15
4-Aug-15
...
14-Aug-15
15-Aug-15
Any help will be appreciated.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.