HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

date

Description

The date of Date / Time for PHP formats a local time/date.

Syntax

date(
    string $format,
    ?int $timestamp = null
): string

Parameters

format

The format of the outputted date string.

There are also several predefined date constants that may be used instead, so for example DATE_RSS contains the format string 'D, d M Y H:i:s'.

DayDescriptionExample
dDay of the month with leading zeros, 2 digits01 - 31
DShort textual representation of the day of the week, three lettersMon - Sun
jDay of the month without leading zeros1 - 31
l (lowercase L)Full textual representation of the day of the weekSunday - Saturday
NISO-8601 numeric representation of the day of the week1 - 7 (Monday - Sunday)
SEnglish ordinal suffix for the day of the month, 2 charactersst, nd, rd, th
wNumeric representation of the day of the week0 - 6 (Sunday - Saturday)
zDay of the year0 - 365
WeekDescriptionExample
WISO-8601 week of the year, weeks start on Monday1 - 52
MonthDescriptionExample
FFull textual representation of a monthJanuary - December
mNumeric representation of a month with leading zeros, 2 digits01 - 12
MShort textual representation of a month, three lettersJan - Dec
nNumeric representation of a month without leading zeros1 - 12
tNumber of days in the given month28 - 31
YearDescriptionExample
LWhether it's a leap year1 (leap year), 0 (otherwise)
oISO-8601 week-numbering year. The same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead.Example: 1999
y2 digit representation of a year00 - 99
Y4 digit representation of a yearExample: 1999
TimeDescriptionExample
aLowercase Ante meridiem and Post meridiemam, pm
AUppercase Ante meridiem and Post meridiemAM, PM
BSwatch Internet time000 - 999
g12-hour format of an hour without leading zeros1 - 12
G24-hour format of an hour without leading zeros0 - 23
h12-hour format of an hour with leading zeros01 - 12
H24-hour format of an hour with leading zeros00 - 23
iMinutes with leading zeros00 - 59
sSeconds with leading zeros00 - 59
uMicroseconds. Note: date() will always generate 000000 since it takes an integer parameter, whereas DateTime::format() does support microseconds if DateTime was created with microseconds.Example: 654321
vMilliseconds. Same note as u.Example: 654
TimezoneDescriptionExample
eTimezone identifierExamples: UTC, GMT, Atlantic/Azores
I (uppercase i)Whether or not the date is in daylight saving time1 (daylight saving time), 0 (otherwise)
ODifference to Greenwich time (GMT) without colon between hours and minutesExample: +0200
PDifference to Greenwich time (GMT) with colon between hours and minutesExample: +02:00
TTimezone abbreviationExamples: EST, MDT ...
ZTimezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.-43200 - 50400
FullDescriptionExample
cISO 8601 dateExample: 2001-02-03T04:05:06+00:00
rRFC 2822 formatted dateExample: Sat, 03 Feb 2001 04:05:06 +0000
USeconds since the Unix Epoch (January 1 1970 00:00:00 GMT)See also time()

Unrecognized characters in the format string will be printed as-is. The Z format will always return 0 when using gmdate(). Note: Since this function only accepts integer timestamps the u format character is only useful when using the date_format() function with user based timestamps created with date_create().

timestamp

The optional timestamp parameter is an integer Unix timestamp that defaults to the current local time if a timestamp is not given. In other words, it defaults to the value of time().

Return

Returns a formatted date string.

Examples

1 · format

<?

$format = "Y-m-d H:i:s";

$return = date($format);

echo $return;
2026-01-19 11:48:50

2 · timestamp · mktime

<?

$hour = 4;
$minute = 5;
$second = 6;
$month = 2;
$day = 3;
$year = 2001;

$format = "Y-m-d H:i:s";
$timestamp = mktime($hour, $minute, $second, $month, $day, $year);

$return = date($format, $timestamp);

echo $return;
2001-02-03 04:05:06

3 · timestamp · strtotime

<?

$datetime = "fourth thursday of november";

$format = "Y-m-d H:i:s";
$timestamp = strtotime($datetime);

$return = date($format, $timestamp);

echo $return;
2026-11-26 00:00:00

4 · constants

<?

echo
date(DATE_ATOM). PHP_EOL.
date(DATE_COOKIE). PHP_EOL.
date(DATE_RSS). PHP_EOL.
date(DATE_W3C);
2026-01-19T11:48:50+00:00
Monday, 19-Jan-2026 11:48:50 UTC
Mon, 19 Jan 2026 11:48:50 +0000
2026-01-19T11:48:50+00:00

5 · characters

<?

echo "day". PHP_EOL.
"d: ". date("d"). PHP_EOL.
"D: ". date("D"). PHP_EOL.
"j: ". date("j"). PHP_EOL.
"l: ". date("l"). PHP_EOL.
"N: ". date("N"). PHP_EOL.
"S: ". date("S"). PHP_EOL.
"w: ". date("w"). PHP_EOL.
"z: ". date("z"). PHP_EOL.
PHP_EOL.

"week". PHP_EOL.
"W: ". date("W"). PHP_EOL.
PHP_EOL.

"month". PHP_EOL.
"F: ". date("F"). PHP_EOL.
"m: ". date("m"). PHP_EOL.
"M: ". date("M"). PHP_EOL.
"n: ". date("n"). PHP_EOL.
"t: ". date("t"). PHP_EOL.
PHP_EOL.

"year". PHP_EOL.
"L: ". date("L"). PHP_EOL.
"o: ". date("o"). PHP_EOL.
"y: ". date("y"). PHP_EOL.
"Y: ". date("Y"). PHP_EOL.
PHP_EOL.

"time". PHP_EOL.
"a: ". date("a"). PHP_EOL.
"A: ". date("A"). PHP_EOL.
"B: ". date("B"). PHP_EOL.
"g: ". date("g"). PHP_EOL.
"G: ". date("G"). PHP_EOL.
"h: ". date("h"). PHP_EOL.
"H: ". date("H"). PHP_EOL.
"i: ". date("i"). PHP_EOL.
"s: ". date("s"). PHP_EOL.
"u: ". date("u"). PHP_EOL.
"v: ". date("v"). PHP_EOL.
PHP_EOL.

"timezone". PHP_EOL.
"e: ". date("e"). PHP_EOL.
"I: ". date("I"). PHP_EOL.
"O: ". date("O"). PHP_EOL.
"P: ". date("P"). PHP_EOL.
"T: ". date("T"). PHP_EOL.
"Z: ". date("Z"). PHP_EOL.
PHP_EOL.

"full". PHP_EOL.
"c: ". date("c"). PHP_EOL.
"r: ". date("r"). PHP_EOL.
"U: ". date("U");
day
d: 19
D: Mon
j: 19
l: Monday
N: 1
S: th
w: 1
z: 18

week
W: 04

month
F: January
m: 01
M: Jan
n: 1
t: 31

year
L: 0
o: 2026
y: 26
Y: 2026

time
a: am
A: AM
B: 533
g: 11
G: 11
h: 11
H: 11
i: 48
s: 50
u: 000000
v: 000

timezone
e: UTC
I: 0
O: +0000
P: +00:00
T: UTC
Z: 0

full
c: 2026-01-19T11:48:50+00:00
r: Mon, 19 Jan 2026 11:48:50 +0000
U: 1768823330

6 · escape

<?

$format = 'l \t\h\e jS \o\f F Y \a\t h:i:s A';

$return = date($format);

echo $return;
Monday the 19th of January 2026 at 11:48:51 AM