How do you display the current date and format it?

How do you display the date and format it?
With the date function as shown in the example below.

echo date('d-F-Y');
echo date('jS F Y');

The output shown below is a sample of the date format that would be displayed. The actual date displayed would be the current date if using the code above.

5th December 2012

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.


Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.