Cover by Rasmus Lerdorf, Peter MacIntyre, Kevin Tatroe

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Chapter 17. Dates and Times

The typical PHP developer likely needs to be aware of the date and time functions available to them, such as when adding a date stamp to a database record entry or calculating the difference between two dates. PHP provides a DateTime class that can be used to handle date and time information at the same time. There is also a DateTimeZone class that works hand in hand with it.

Time zone management has become more prominent in recent years with the onset of web portals and social web communities like Facebook and Twitter. To be able to post information to a website and have it recognize where you are in the world in relation to others on the same site is definitely a requirement these days. However, keep in mind that a function like date() takes the default information from the server on which the script is running, so unless the human client tells you where they are in the world, it can be quite difficult to determine time zone location automatically. Once you know the information though, it’s easy to manipulate that data (more on time zones later in this chapter).

Note

The original date (and related) functions have a timing flaw in them (in versions prior to 5.1) on Windows and some Unix installations. They cannot process dates prior to January 1, 1970, or dates beyond January 19, 2038, due to the nature of the underlying 32-bit signed integer used to manage the date and time data. Therefore, it is better to use the newer DateTime class family for better ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required