The date() function converts a given timestamp into a readable date format.
Here is the syntax for this function:
Syntax
[code lang=”php”]
date(format,timestamp);
[/code]
Parameters:
format
This parameter determines the format and how the date will read.
For example: “Saturday, Nov. 16th 2009” would be the following code:
[code lang=”php”]
$timestamp = time();
date(“l, M. jS Y”,$timestamp);
[/code]
timestamp
This parameter is the timestamp you want to use to format a date from. This timestamp is a number of seconds since a certain date, since we used the current timestamp of time() we are making the date for the current time.
We’ll break down our example to see what each set of letters represents as part of the date’s format.
- l – day of the week, textual, long; i.e. ‘Friday’
- M – month, textual, 3 letters; i.e. ‘Jan’
- j – day of the month without leading zeros; i.e. ’1′ to ’31′
- S – English ordinal suffix, textual, 2 characters; i.e. ‘th’,‘nd’
- Y – year, 4 digits; i.e. ’1999′