Working with Date and Time

Being able to work easily with date and time information is one of the most basic skills every PHP programmer should get under their belt as soon as possible, so this is where we will be kicking off.

PHP represents time as the number of seconds that have passed since January 1st 1970 00:00:00 GMT, a date known as the start of the Unix epoch, hence this date format is known as "epoch time" or a "Unix timestamp". This might seem like a peculiar way to store dates, but it is actually remarkably good - internally you can store any date since 1970 as an integer, and convert to a human-readable string wherever necessary.


Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Reading the current time >>

Previous chapter: Controlling script execution

Jump to:


Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.