brenlei.com

PHP tutorials

Question:

How do you display the date and format it?

Answer:

With the date function as shown in the example below.

echo date('d-F-Y');
echo date('jS F Y');
Output
05-December-2005
5th December 2005
Additional notes

There are 31 format flags that can be used with the date function. Characters that are not recognized as format flags are printed as-is, as shown with the first example with the dashes.

The date function also takes an optional second parameter which is the timestamp in seconds. This is the UNIX timestamp, measured in seconds since January 1st 1970.

PHP Reference Manual

date - Returns a formatted date

Comments or questions relating to this article have been disabled. They will be back soon.