1. Home
  2. PHP Date Format

PHP Date Format

Type a PHP date() format string and see the result as you type. Below is every format character with an example.

Monday, October 26th, 2026 at 2:05 PM

The live preview is a JavaScript port of date(). “Confirm with real PHP” runs the same format through PHP 8.4 in your browser.

PHP date() format characters

Examples use Monday, October 26, 2026, 14:05:09 UTC. Any other character is printed as is; escape letters with a backslash.

Day
dDay of the month, 2 digits with leading zeros (01 to 31)26
DDay of the week, three letters (Mon to Sun)Mon
jDay of the month without leading zeros (1 to 31)26
lFull day of the week (Sunday to Saturday)Monday
NISO 8601 day of the week, 1 (Monday) to 7 (Sunday)1
SEnglish ordinal suffix for the day: st, nd, rd or th. Works well with jth
wDay of the week, 0 (Sunday) to 6 (Saturday)1
zDay of the year, starting from 0 (0 to 365)298
Week
WISO 8601 week number of the year, weeks start on Monday44
Month
FFull month name (January to December)October
mMonth with leading zeros (01 to 12)10
MMonth, three letters (Jan to Dec)Oct
nMonth without leading zeros (1 to 12)10
tNumber of days in the month (28 to 31)31
Year
LLeap year: 1 if it is, 0 otherwise0
oISO 8601 week-numbering year, matches W2026
XExpanded year with sign, at least 4 digits (PHP 8.2+)+2026
xExpanded year if needed, otherwise like Y (PHP 8.2+)2026
YFull year, at least 4 digits2026
yTwo-digit year26
Time
aLowercase am or pmpm
AUppercase AM or PMPM
BSwatch Internet time (000 to 999)628
g12-hour hour without leading zeros (1 to 12)2
G24-hour hour without leading zeros (0 to 23)14
h12-hour hour with leading zeros (01 to 12)02
H24-hour hour with leading zeros (00 to 23)14
iMinutes with leading zeros (00 to 59)05
sSeconds with leading zeros (00 to 59)09
uMicroseconds. date() always prints 000000; DateTime::format() prints real values000000
vMilliseconds. date() always prints 000000
Time zone
eTime zone identifier, e.g. UTC or Europe/BerlinUTC
IDaylight saving time: 1 if in effect, 0 otherwise0
ODifference to UTC without colon, e.g. +0200+0000
PDifference to UTC with colon, e.g. +02:00+00:00
pLike P, but Z for +00:00 (PHP 8.0+)Z
TTime zone abbreviation, e.g. UTC, EST, CESTUTC
ZOffset from UTC in seconds (-43200 to 50400)0
Full date/time
cISO 8601 date, e.g. 2026-10-26T14:05:09+00:002026-10-26T14:05:09+00:00
rRFC 2822 date, e.g. Mon, 26 Oct 2026 14:05:09 +0000Mon, 26 Oct 2026 14:05:09 +0000
USeconds since the Unix epoch (January 1, 1970 UTC)1793023509

Common PHP date formats

FormatResultUse
Y-m-d H:i:s2026-10-26 14:05:09MySQL DATETIME
Y-m-d2026-10-26ISO date
c2026-10-26T14:05:09+00:00ISO 8601
D, d M Y H:i:s \G\M\TMon, 26 Oct 2026 14:05:09 GMTHTTP header
l, F jS, YMonday, October 26th, 2026Long US
d/m/Y26/10/2026Day first
m/d/Y10/26/2026Month first
g:i A2:05 PM12-hour time
U1793023509Unix timestamp

PHP also has constants for standard formats, so you do not have to remember them: DATE_ATOM (Y-m-d\TH:i:sP, the format JSON APIs and <input type="datetime-local"> expect), DATE_RFC2822 for email headers, DATE_RSS for feeds and DATE_COOKIE for cookies. Use them as date(DATE_ATOM) or $dt->format(DateTimeInterface::ATOM).

date() or DateTime?

date() is fine for quick output of the current time. For anything else, use DateTimeImmutable: it carries its own time zone, does calendar arithmetic correctly with modify('+1 month') and add(new DateInterval('P1D')), supports microseconds, and avoids the year 2038 limit that 32-bit timestamps had. Its format() method uses exactly the characters listed above.

$dt = new DateTimeImmutable('now', new DateTimeZone('America/New_York'));
echo $dt->format('D, M j, Y g:i A T');   // Mon, Oct 26, 2026 10:05 AM EDT
echo $dt->modify('last day of this month')->format('Y-m-d');

Paste these lines into the PHP Sandbox to see them run.

Format characters that trip people up

  • m and i: m is the month, i is minutes. Y-m-d H:m is a classic bug that prints the month where minutes should be.
  • h and H: lowercase is the 12-hour clock, so pair it with A. Uppercase is 24-hour.
  • D and d: uppercase is the weekday name, lowercase is the day number.
  • S: only makes sense right after j, as in jS for “26th”.
  • W with Y: use o instead of Y next to the ISO week number.
  • Localised names: date() always prints English names. For other languages, use IntlDateFormatter from the intl extension.

More PHP tools

Frequently asked questions

How do I format a date in PHP?

Call date($format) for the current time or date($format, $timestamp) for another moment. For example, date('Y-m-d H:i:s') prints 2026-10-26 14:05:09. With a DateTime object, use $dt->format('Y-m-d'); both use the same format characters.

How do I print a letter that is also a format character?

Escape it with a backslash. date('\T\o\d\a\y \i\s l') prints “Today is Monday”. In double-quoted PHP strings you need two backslashes for sequences like \n and \t, so single quotes are easier.

What is the difference between Y and o?

Y is the calendar year. o is the ISO 8601 week-numbering year, which belongs with W. They differ for a few days around New Year: December 29, 2025 is in ISO week 1 of 2026, so o-W gives 2026-01 while Y-W would give the wrong 2025-01.

Why does date() show the wrong time?

PHP uses the default time zone from date.timezone in php.ini, which is often UTC on servers. Set it in php.ini or call date_default_timezone_set('Europe/Berlin'), or better, create new DateTime('now', new DateTimeZone('Europe/Berlin')) so the zone is explicit.

How do I get milliseconds or microseconds?

date() works with whole-second timestamps, so u and v always print zeros. Use DateTime: (new DateTime())->format('Y-m-d H:i:s.v') prints milliseconds, and u prints microseconds.

How do I convert a date string from one format to another?

Parse it with DateTime::createFromFormat(), then format it: DateTime::createFromFormat('d/m/Y', '26/10/2026')->format('Y-m-d') returns 2026-10-26. strtotime() also works for common English formats, but it guesses, and 01/02/2026 is read as January 2.