Chapter 9. Working with Dates and Times

In this lesson you will learn how to store, display, and manipulate date and time values in PHP.

Date Formats

PHP does not have a native date data type, so in order to store date values in a script, you must first decide on the best way to store these values.

Do-It-Yourself Date Formats

Although you often see dates written in a structured format, such as 05/03/1974 or 2001-12-31, these are not ideal formats for working with date values. However, the latter of these two is more suitable than the first because the order of its components is from most significant (the year) to the least significant (the day), so values can be compared using the usual PHP operators.

As a string, 2002-01-01 is greater than 2001-12-31 ...

Get Sams Teach Yourself PHP in 10 Minutes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.