Converting a Timestamp with date()

You can use getdate() when you want to work with the elements it outputs. Sometimes, though, you only want to display the date as a string. The date() function returns a formatted string representing a date. You can exercise an enormous amount of control over the format that date() returns with a string argument you must pass to it. In addition to the format string, date() optionally accepts a timestamp. Table 16.2 lists the codes a format string can contain; any other data you include in the format string passed to date() is included in the return value.

Table 16.2. Format Codes for Use with date()
FormatDescriptionExample
aam or pm lowercasepm
AAM or PM uppercasePM
BSwatch beat (timezone-free ’Internet time’) ...

Get Sams Teach Yourself PHP in 24 Hours, Third Edition 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.