PHP Date() Function

The date() function converts a given timestamp into a readable date format.

Here is the syntax for this function:

Syntax

date(format,timestamp);

Parameters:

format
This parameter determines the format and how the date will read.

For example: “Saturday, Nov. 16th 2009” would be the following code:

$timestamp = time();
date("l, M. jS Y",$timestamp);

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′

View the complete date format reference here.

0

Popularity: 1% [?]

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Filed Under: PHPWeb Programming

Tags:

RSSComments (0)

Trackback URL

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.

The tutorials and scripts found on bgallz.org are for training purposes only, use to your discretion.