PHP

Date Formatting Symbols for date()

Symbol

Description

a

am or pm

A

AM or PM

B

Swatch Internet Time (between 000 and 999)

c

Date in ISO 8601 format

d

Day of month (from 01 to 31)

D

Day of week (from Mon to Sun)

F

Month (from January to December)

g

Hour (from 1 to 12)

G

Hour (from 0 to 23)

h

Hour (from 01 to 12)

H

Hour (from 00 to 23)

i

Minutes (from 00 to 59)

I

Whether date is in DST (1) or not (0)

j

Day of month (between 1 and 31)

l

Day of month (from Sunday to Saturday)

L

Whether date is in a leap year (1) or not (0)

m

Month (from 01 to 12)

M

Month (from Jan to Dec)

n

Month (from 1 to 12)

O

Difference to GMT (for example, +0100 for one hour ahead)

r

Date in RFC 2822 format

s

Seconds (from 00 to 59)

S

Ordinal suffix for the day of month (st, nr, td, th)

t

Number of days in the provided month (from 28 to 31)

T

Time zone of server (for example, CET)

U

Epoche value (seconds since January 1st, 1970, Midnight GMT)

w

Day of week (from 0Sunday, to 6Saturday)

W

Week number (according to ISO 8601, from 1 to 53)

y

Year (two digits)

Y

Year (four digits)

z

Day of year (from 0 to 365)

Z

Time zone difference to UTC (in seconds)


Almost all of the formatting symbols shown in above table are available since PHP 3. There are only two exceptions: Using W for determining the week number of a date was added in PHP 4.1.0, and using c for retrieving the ISO 8601 representation for a date (for example, 2006-06-30T12:34:56+01:00) came in PHP 5.

The function date() is very powerful and offers a broad range of ways to use it. However, especially if you have localized content, you need some good code. In this chapter, you will find many of them.

PHP's date and time functions have their own section in the PHP manual. You can find more information about date() and friends at http://php.net/datetime.

by BrainBellupdated
Advertisement: