logoPHP Date and Time
Crib Sheets
Home Page
Beds
Bolts
Chemistry
Clothing
Convert Unit
Electrical
First Aid
Food/Drink
Radio Freq.
History
Geography
Geology
Mathematics
Music
Nautical
Numbers
Paper Sizes
Physics
Signs
Weather
Entities
PHP Dates
PHP Timezones
DigitalDan Home
Hit = 103
 
©2000-2023
DigitalDan
 
Contact Site

PHP Date() Codes

The examples below relate to timezone = GMT, date = Sun 2 Jan 2028 and to time = 07:08:09 (8 minutes and 9 seconds past 7am)

CodeDescription
Example result
aam/pm
am
AAM/PM
AM
BSwatch Time (0-999)
297
cISO 8601 date
2028-01-02T07:08:09+00:00
dDay of the month (01 - 31)
02
DDay (Sun - Sat)
Sun
eTimezone (GMT PST EST …)
GMT
FMonth (January - December)
January
gHour (1 - 12)
7
GHour (0 - 23)
7
hHour (01 - 12)
07
HHour (00 - 23)
07
iMinute (00 - 59)
08
IIs Daylight Saving Time (1=true 0-false)
0
jDay of Month (1 - 31)
2
lDay (Monday - Sunday)
Sunday
LIs Leap Year (1=true 0=false)
0
mMonth (01 - 12)
01
MMonth (Jan - Dec)
Jan
NISO Weekday (1=Monday 7=Sunday)
7
nMonth (1-12)
1
oYear for ISO Week Number
2027
OGMT Offset hhmm
+0000
PGMT Offset hh:mm
+00:00
pGMT offset hh:mm or Z (Z=+00:00)
Z
rRFC2822/RFC5322 date
Sun, 2 Jan 2028 07:08:09 +0000
SDay ordinal suffix (st, nd, rd or th)
nd
sSeconds (00 - 59)
09
tDays in month (28, 29, 30 or 31)
31
TTimezone (GMT, EST, PST, +02 … )
GMT
uMicroseconds (often returns 0)
000000
UUnix Epoch (Seconds since 1 Jan 1970)
1830409689
vMilliseconds (often returns 0)
000
wDay of Week (0=Sunday 6=Saturday)
0
WISO Week Number
52
XYear (4 or 5 digits) (-9999 - +19999)
+2028
xYear (4 or 5 digits) (-9999 - 9999 or +10000 - +19999)
2028
YYear (4 or 5 digits) (-9999 - 19999
2028
yYear (2 digits) (00 - 99)
28
zDay of year (0 - 365)
1
ZTimezone UTC offset seconds (-43200 - 50400)
0

PHP getdate() Codes

ElementDescription
Example result
secondsSeconds (0 - 59)
9
minutesMinutes (0 - 59)
8
hoursHours (0 - 23)
7
mdayDay (1 - 31)
2
wdayDay (0=Sunday 6=Saturday)
0
monMonth (1-12)
1
yearYear (0000 - 9999)
2028
ydayDay of year (0 - 365)
1
weekdayDay (Sunday - Saturday)
Sunday
monthMonth (January - December)
January
0Seconds since 1970
1830409689

When working with dates or times in PHP, it is important to ensure the test environment is using the same timezone as your live website server. Ignoring timezones can create strange time errors. These can suddenly appear, long after the page goes live. (Time/date timezone errors often appear on dates linked to the European or American Summer/Winter time boundaries.

Adding the line
date_default_timezone_set('xxxxx');
to the start of your PHP script will ensure consistent behaviour. (Replace xxxxx with an appropriate timezone. The timezone Europe/London correctly adjust for UK Wintertime(GMT) and Summertime (BST).

This site is based in the UK, hence I use line
date_default_timezone_set('Europe/London');

Timezones normally consist of three parts - The name of a continent or ocean (e.g. Europe), the separator character / and the name of the large city within the timezone (e.g. London);
A few timezones use Continent/State/City or Continent/Country

 

www.DigitalDan.co.uk