PHP date() Function Format Characters
Reference for PHP's date() format characters. Learn single-letter tokens for year, month, day, time, timezone, and how they differ from other languages' format strings.
Detailed Explanation
PHP date() Format Characters
PHP's date() function uses single-letter format characters — a system that is unique among programming languages and requires memorization since the letters are not always intuitive.
Format Characters
| Char | Meaning | Example |
|---|---|---|
Y |
Year (4-digit) | 2026 |
y |
Year (2-digit) | 26 |
m |
Month (zero-padded) | 02 |
n |
Month (no padding) | 2 |
F |
Full month name | February |
M |
Abbreviated month | Feb |
d |
Day (zero-padded) | 28 |
j |
Day (no padding) | 28 |
S |
Ordinal suffix | th |
l |
Full weekday (lowercase L) | Saturday |
D |
Abbreviated weekday | Sat |
N |
Weekday (1=Monday, 7=Sunday) | 6 |
w |
Weekday (0=Sunday) | 6 |
H |
Hour 24h (zero-padded) | 14 |
G |
Hour 24h (no padding) | 14 |
h |
Hour 12h (zero-padded) | 02 |
g |
Hour 12h (no padding) | 2 |
i |
Minutes (zero-padded) | 30 |
s |
Seconds (zero-padded) | 00 |
A |
AM/PM (uppercase) | PM |
a |
am/pm (lowercase) | pm |
U |
Unix timestamp | 1772236800 |
z |
Day of year (0-365) | 58 |
W |
ISO week number | 09 |
P |
Timezone offset (+HH:MM) | +09:00 |
O |
Timezone offset (+HHMM) | +0900 |
T |
Timezone abbreviation | JST |
Usage
echo date("Y-m-d H:i:s"); // 2026-02-28 14:30:00
echo date("F j, Y, g:i a"); // February 28, 2026, 2:30 pm
echo date("D, d M Y H:i:s O"); // Sat, 28 Feb 2026 14:30:00 +0900
echo date("jS \o\f F Y"); // 28th of February 2026
Escaping Characters
Any character that is not a format character is included as-is. To include a character that happens to be a format character, escape it with a backslash:
echo date("\T\o\d\a\y \i\s: l"); // "Today is: Saturday"
Predefined Constants
PHP provides constants for common formats:
DATE_ATOM // "Y-m-d\TH:i:sP" → 2026-02-28T14:30:00+09:00
DATE_ISO8601 // "Y-m-d\TH:i:sO" → 2026-02-28T14:30:00+0900
DATE_RFC2822 // "D, d M Y H:i:s O" → Sat, 28 Feb 2026 14:30:00 +0900
DATE_RSS // Same as RFC 2822
Use Case
PHP date() is used in WordPress theme development, Laravel Blade templates, database query date formatting, email header generation, cache control headers, and log file timestamps. The Carbon library (built on PHP's DateTime) extends these capabilities with relative time and timezone fluency.