Date and Time Functions
Last but certainly not least, I’ll introduce a couple of PHP’s date- and time-related functions. The most important of these is the aptly named date() function, which returns a string of text for a certain date and time according to a format you specify.
date (format, [timestamp]);
The timestamp is an optional argument representing the number of seconds since the Unix Epoch (midnight on January 1, 1970) for the date in question. If not specified, PHP will just use the current time on the server.
There are myriad formatting parameters available (Table 3.1) and these can be used in conjunction with straight text. For example,
echo date('F j, Y'); // January 21, 2003 echo date('H:i'); // 23:14 echo date('D'); // Mon ...
Get PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide 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.