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

date_format

Description

The date_format of Date / Time for PHP returns date formatted according to given format.

Syntax

date_format(
    DateTimeInterface $object,
    string $format
): string

Parameters

object

A DateTime object returned by date_create()

format

The format of the outputted date string.

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
Y4 digit representation of a yearExample: 1999
y2 digit representation of a year00 - 99
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().

Return

Returns the formatted date string on success.

Examples

1 · object format

<?

$object = date_create();
$format = "Y-m-d h:i:s.u";

$return = date_format($object, $format);

echo $return;
2026-01-14 11:12:03.491574