troubleshooting Question

Looping through dates, but October 2016 displays Sun 30th Oct twice - but no Mon 31st Oct?! All other 2016 months displays fine.

Avatar of Jamie
JamieFlag for United Kingdom of Great Britain and Northern Ireland asked on
PHP
6 Comments2 Solutions133 ViewsLast Modified:
Hello EE,

This has been driving me nuts, as I'm sure it is my error somewhere, but cannot work it out? Why does, when looping through with my php code,  1st to 31st October 2016, does it display Sun 30th October twice and no Mon 31st Oct?! All other 2016 months display fine?

date_default_timezone_set('Europe/London');

echo '<br /><strong>October</strong><br />';
$date_from = strtotime('2016-10-01');
$date_to = strtotime('2016-10-31');

for ($i = $date_from; $i <= $date_to; $i+= 86400)
{
echo date("D", $i) . " " . date("jS", $i) . " " . date("M", $i) . "<br />";
}

Gives;

October
Sat 1st Oct
Sun 2nd Oct
Mon 3rd Oct
Tue 4th Oct
Wed 5th Oct
Thu 6th Oct
Fri 7th Oct
Sat 8th Oct
Sun 9th Oct
Mon 10th Oct
Tue 11th Oct
Wed 12th Oct
Thu 13th Oct
Fri 14th Oct
Sat 15th Oct
Sun 16th Oct
Mon 17th Oct
Tue 18th Oct
Wed 19th Oct
Thu 20th Oct
Fri 21st Oct
Sat 22nd Oct
Sun 23rd Oct
Mon 24th Oct
Tue 25th Oct
Wed 26th Oct
Thu 27th Oct
Fri 28th Oct
Sat 29th Oct
Sun 30th Oct
Sun 30th Oct


Whereas November and December 2016 work fine;

November
Tue 1st Nov
Wed 2nd Nov
Thu 3rd Nov
Fri 4th Nov
Sat 5th Nov
Sun 6th Nov
Mon 7th Nov
Tue 8th Nov
Wed 9th Nov
Thu 10th Nov
Fri 11th Nov
Sat 12th Nov
Sun 13th Nov
Mon 14th Nov
Tue 15th Nov
Wed 16th Nov
Thu 17th Nov
Fri 18th Nov
Sat 19th Nov
Sun 20th Nov
Mon 21st Nov
Tue 22nd Nov
Wed 23rd Nov
Thu 24th Nov
Fri 25th Nov
Sat 26th Nov
Sun 27th Nov
Mon 28th Nov
Tue 29th Nov
Wed 30th Nov

December
Thu 1st Dec
Fri 2nd Dec
Sat 3rd Dec
Sun 4th Dec
Mon 5th Dec
Tue 6th Dec
Wed 7th Dec
Thu 8th Dec
Fri 9th Dec
Sat 10th Dec
Sun 11th Dec
Mon 12th Dec
Tue 13th Dec
Wed 14th Dec
Thu 15th Dec
Fri 16th Dec
Sat 17th Dec
Sun 18th Dec
Mon 19th Dec
Tue 20th Dec
Wed 21st Dec
Thu 22nd Dec
Fri 23rd Dec
Sat 24th Dec
Sun 25th Dec
Mon 26th Dec
Tue 27th Dec
Wed 28th Dec
Thu 29th Dec
Fri 30th Dec
Sat 31st Dec

What am I doing wrong?

Many thanks

Jamie
SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros