PHP

Date and Time

Most of the time, the date and time functionalities of PHP 5 are used for printing out the current date and time to pretend that the web page is up to date (you would be surprised how many larger websites actually use this). But apart from that, working with date and time in PHP offers many other possibilities, most of which you will find in this chapter.

First, though, it seems appropriate to have a look at the PHP function that is probably used the most for working with datesdate(). This function can take the current date (or an arbitrary one) and extract some information about it, for example, the day, whether it's a.m. or p.m., and what time it is according to the rather failed marketing stunt, "Swatch Internet Time." To do so, you call date() and provide a string as the first parameter. This string may now contain a list of formatting symbols that can be seen in next page (the PHP manual carries a list with more examples at http://php.net/date). Each of these symbols is replaced by the associated date/time value.