Date and Time – PHP way – part 3

Today third and final part. Today we will talk mainly about DatePeriod class. It is very powerful tool, we can use it to iterate dates. How about iterating all Fridays? We like Fridays, because weekend starts, so… it is always good to know it’s Friday 🙂 Let’s begin…

And results:

I think this is self explanatory code. Please remember three things.

One – I used next friday as an interval. If you use last friday you’ll get your iterator iterating downwards, so you may end in the year of -9999 🙂

Two – $item is DateTime object, you may do whatever you want as it’s normal object

Three – this is iterator, not an array, so count() won’t work!