PHP: Dominate dates with intervals and periods

Time doesn’t have to be a sin to handle

What’s an interval?

In PHP, the DateInterval object exists to describe the duration of time. For example, 6 days, or 45 minutes. There is no start date, no end date, just duration.

What’s a DatePeriod?

As the name implies, DatePeriod describes multiple moments (periods) across time from an starting point, a given number of times.

  • make complicated functions to know when is the next or previous recurrence, or,
  • add or substract intervals.

The end is tricky

The DatePeriod is VERY useful when dealing with periodic moments. You can even exclude the starting period using the EXCLUDE_START_DATE constant from the list of recurrences. The ending, though, must be handled with care.

Graphic Designer graduate. Full Stack Web Developer. Retired Tech & Gaming Editor.