DMXzone Summer Sale: Save up to 51% with code DMXSUMMER26. Ends in

Dates and Time – The OOP Way

Work with almost all of the date and time related tasks

The Date/Time PHP extension is a set of classes that allow you to work with almost all of the date and time related tasks. It’s been available since the release of PHP 5.2 and the extension introduced several new classes, all of which are mapped to real life scenarios.


  • A date or a time is represented by a DateTime object.
  • A timezone of the world is represented by a DateTimeZone object.
  • DateInterval objects represent an interval. For example, when we say two days from now on, the “two days” is the interval. The DateInterval object doesn’t rely on a specific date or time.
  • DatePeriod objects represent a period between two dates.
All of the classes that we’ve covered today can be extended to use with your own methods. One popular usage is extending the DateTime with a __toString method so that you can properly print out a DateTime object without calling format.

Comments

Be the first to write a comment

You must me logged in to write a comment.