How do you display the current date and format it?

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
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.

05-December-2012
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.

Comments

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.