A PHP date format is a string where letters stand for parts of the date: date('Y-m-d H:i:s') prints something like 2026-03-14 09:05:07. Y is the 4-digit year, m the month, d the day, H the hour (24-hour clock), i the minutes and s the seconds; any character that is not a format letter, such as -, / or :, is printed as it is. The same format strings work in date() and in DateTimeImmutable::format().
Change $format and press Run. The date is fixed to Saturday, March 14, 2026 at 09:05:07, so you can see exactly what each letter does:
Output:
Sat, 14 Mar 2026 09:05
2026-03-14
14/03/2026
Saturday, March 14th, 2026
9:05 AM
date($format) formats the current moment and date($format, $timestamp) a timestamp; $date->format($format) formats a date object. Everything else about dates, from strtotime() to timezones, is on the PHP date() page.
Date format characters
Every example below is the result for 2026-03-14 09:05:07.123456 UTC.
Day
| Character | Meaning | Example |
|---|---|---|
d | Day of the month, 2 digits with leading zero (01 to 31) | 14 |
j | Day of the month without leading zero (1 to 31) | 14 |
D | Short day name, 3 letters | Sat |
l (lowercase L) | Full day name | Saturday |
N | ISO day of the week, 1 (Monday) to 7 (Sunday) | 6 |
w | Day of the week, 0 (Sunday) to 6 (Saturday) | 6 |
S | English suffix for the day: st, nd, rd or th. Use it after j | th |
z | Day of the year, starting at 0 | 72 |
Week and month
| Character | Meaning | Example |
|---|---|---|
W | ISO 8601 week number (weeks start on Monday) | 11 |
F | Full month name | March |
M | Short month name, 3 letters | Mar |
m | Month number with leading zero (01 to 12) | 03 |
n | Month number without leading zero (1 to 12) | 3 |
t | Number of days in the month | 31 |
Year
| Character | Meaning | Example |
|---|---|---|
Y | Full year, at least 4 digits | 2026 |
y | Year, 2 digits | 26 |
L | 1 if it is a leap year, otherwise 0 | 0 |
o | ISO 8601 week-numbering year (use it with W) | 2026 |
X | Expanded full year with a sign (PHP 8.2+) | +2026 |
x | Expanded full year, sign only when needed (PHP 8.2+) | 2026 |
Time
| Character | Meaning | Example |
|---|---|---|
H | Hour, 24-hour clock, leading zero (00 to 23) | 09 |
G | Hour, 24-hour clock, no leading zero (0 to 23) | 9 |
h | Hour, 12-hour clock, leading zero (01 to 12) | 09 |
g | Hour, 12-hour clock, no leading zero (1 to 12) | 9 |
i | Minutes with leading zero (00 to 59) | 05 |
s | Seconds with leading zero (00 to 59) | 07 |
a | am or pm | am |
A | AM or PM | AM |
v | Milliseconds | 123 |
u | Microseconds (always 000000 in date(), which takes whole seconds) | 123456 |
B | Swatch Internet time (000 to 999) | 420 |
Timezone
| Character | Meaning | Example |
|---|---|---|
e | Timezone identifier | UTC |
T | Timezone abbreviation | UTC |
P | Offset from UTC with a colon | +00:00 |
p | Like P, but Z for UTC | Z |
O | Offset from UTC without a colon | +0000 |
Z | Offset in seconds | 0 |
I (capital i) | 1 during daylight saving time, otherwise 0 | 0 |
Full date and time
| Character | Meaning | Example |
|---|---|---|
c | ISO 8601 date and time | 2026-03-14T09:05:07+00:00 |
r | RFC 2822 date, used in email headers | Sat, 14 Mar 2026 09:05:07 +0000 |
U | Unix timestamp (seconds since 1970-01-01 UTC) | 1773479107 |
The same table, live: this block prints every character for a date you choose. Put in your birthday, a date in the afternoon, or one at the end of a leap year:
Print letters and words inside a format
Any letter in a format string is read as a format character, so 'Today is l' does not print "Today is": T, o, d, a, y, i and s are all format characters. Put a backslash before each letter you want printed as it is. In a double-quoted string, \t is already a tab character, so use single quotes for formats with backslashes:
Output:
UTC202614am26 0507 Saturday
Today is Saturday
Saturday the 14th of March
2026-03-14T09:05:07
Saturday 09UTC 14th
Common date formats
Most code needs only a handful of formats. This block prints them as an HTML table, so it shows up on the Page tab:
Store and compare dates as Y-m-d or Y-m-d H:i:s: strings in that order sort the same way the dates do, which d/m/Y strings do not.
ISO 8601, DATE_ATOM and other standard formats
PHP has constants for the formats that APIs, feeds and cookies expect. DATE_ATOM (also DateTimeInterface::ATOM) is ISO 8601 and RFC 3339, the format JSON APIs use:
Output:
2026-03-14T09:05:07+00:00
2026-03-14T09:05:07+00:00
2026-03-14T09:05:07.000+00:00
Sat, 14 Mar 2026 09:05:07 +0000
Sat, 14 Mar 2026 09:05:07 +0000
Saturday, 14-Mar-2026 09:05:07 UTC
Y-m-d\TH:i:sP
There is also a DATE_ISO8601 constant, but its offset has no colon (+0000), which ISO 8601 does not allow in that form; use DATE_ATOM.
Japanese date format (Y年m月d日)
Characters that are not format letters are printed as they are, and that includes kanji, so 'Y年n月j日' works as written. n and j drop the leading zero (3月14日), m and d keep it (03月14日). The day name is the one part date() cannot translate, because it only knows English names; map the w number to your own list instead:
Output:
2026年3月14日
2026年03月14日 09時05分
2026年3月14日(土)
2026/03/14
For full localization, including month names in other languages and the Japanese era (令和), the intl extension's IntlDateFormatter formats with locale patterns. It uses ICU pattern letters (yyyy, MM, EEEE), not the PHP characters on this page:
<?php
$formatter = new IntlDateFormatter('ja_JP', IntlDateFormatter::FULL, IntlDateFormatter::NONE, 'Asia/Tokyo');
echo $formatter->format(new DateTimeImmutable('2026-03-14')); // 2026年3月14日土曜日
$era = new IntlDateFormatter('ja_JP@calendar=japanese', IntlDateFormatter::LONG, IntlDateFormatter::NONE, 'Asia/Tokyo', IntlDateFormatter::TRADITIONAL);
echo $era->format(new DateTimeImmutable('2026-03-14')); // 令和8年3月14日
Convert a date from one format to another
To turn 14/03/2026 into 2026-03-14, parse the string with the format it is written in, using DateTimeImmutable::createFromFormat(), then format it again. It uses the same characters as the table. Start the format with !, or fields you did not give (the time, here) are filled in from the current moment:
Output:
2026-03-14 00:00:00
March 14, 2026
bool(false)
2026-03-03
Array
(
[10] => The parsed date was invalid
)
For dates typed by users, treat any warning from getLastErrors() as an invalid date, the same way you treat false.
Common mistakes with date formats
Three bugs show up again and again: m where i was meant, Y versus y, and letting strtotime() guess the order of day and month. strtotime() reads slashes as American month/day order and dashes or dots as day-month order, so the same digits give two different dates:
Output:
09:03:07
09:05:07
14/03/26
2026-03-04
2026-04-03
bool(false)
When you know the format of the input, say it with createFromFormat() instead of letting strtotime() guess.
Frequently Asked Questions
What does date('Y-m-d') mean in PHP?
Each letter is replaced by a part of the date: Y is the year with 4 digits, m the month with a leading zero and d the day with a leading zero, and the dashes are printed as they are. On March 14, 2026 it returns 2026-03-14.
How do I convert a date from one format to another in PHP?
Parse it with the format it is in, then format it with the one you want: DateTimeImmutable::createFromFormat('!d/m/Y', '14/03/2026')->format('Y-m-d') returns 2026-03-14. createFromFormat() returns false when the string does not match, so check that first.
What is the difference between m and i in a PHP date format?
m is the month (01 to 12) and i is the minutes (00 to 59). Writing 'H:m' instead of 'H:i' is a common bug: the time shows the month number where the minutes should be.
How do I format a date as ISO 8601 in PHP?
Use the c character or the DATE_ATOM constant: $date->format(DATE_ATOM) returns 2026-03-14T09:05:07+00:00. Avoid DATE_ISO8601: its offset has no colon (+0000), which is not valid ISO 8601.
How do I show the day of the week in Japanese with PHP date()?
date() only prints English names, so map the w number (0 for Sunday to 6 for Saturday) to your own list: ['日','月','火','水','木','金','土'][$date->format('w')]. With the intl extension, IntlDateFormatter can format whole dates in any locale.