PHP DateTime Formatter

Format a date with any PHP date() pattern — or paste an example and detect the format string. Works for full dates and time-only values.

Input

Common formats

Output

Formatted result 2024-01-15 13:45:30
Token breakdown
Y 2024literal -m 01literal -d 15literal H 13literal :i 45literal :s 30
PHP code
$date = new DateTime('2024-01-15 13:45:30');
echo $date->format('Y-m-d H:i:s'); // 2024-01-15 13:45:30

Format character reference

Click a row to add it to your format

Example values are computed from the date currently selected above.

Day
dDay of the month, 2 digits with leading zeros (01–31)15
jDay of the month without leading zeros (1–31)15
DDay name, three letters (Mon–Sun)Mon
lFull day name (Sunday–Saturday)Monday
NISO day of week (1 = Monday … 7 = Sunday)1
wDay of week, numeric (0 = Sunday … 6 = Saturday)1
SEnglish ordinal suffix (st, nd, rd, th)th
zDay of the year, zero-indexed (0–365)14
Week
WISO-8601 week number of the year03
Month
mMonth, 2 digits with leading zeros (01–12)01
nMonth without leading zeros (1–12)1
MMonth name, three letters (Jan–Dec)Jan
FFull month name (January–December)January
tNumber of days in the given month (28–31)31
Year
YFull numeric year, 4 digits (e.g. 2024)2024
yTwo-digit year (e.g. 24)24
LLeap year (1 if leap, 0 otherwise)1
oISO-8601 week-numbering year2024
Time
H24-hour format with leading zeros (00–23)13
G24-hour format without leading zeros (0–23)13
h12-hour format with leading zeros (01–12)01
g12-hour format without leading zeros (1–12)1
iMinutes with leading zeros (00–59)45
sSeconds with leading zeros (00–59)30
AUppercase AM or PMPM
aLowercase am or pmpm
vMilliseconds (e.g. 654)000
uMicroseconds (e.g. 654000)000000
BSwatch Internet time (000–999)614
Timezone
eTimezone identifier (UTC in this tool)UTC
TTimezone abbreviation (UTC in this tool)UTC
OOffset to GMT, no colon (e.g. +0000)+0000
POffset to GMT, with colon (e.g. +00:00)+00:00
ZTimezone offset in seconds0
IDaylight saving time (1 or 0)0
Full Date/Time
cISO-8601 date (2004-02-12T15:19:21+00:00)2024-01-15T13:45:30+00:00
rRFC 2822/5322 formatted dateMon, 15 Jan 2024 13:45:30 +0000
USeconds since the Unix Epoch1705326330

About PHP DateTime Formatter

PHP DateTime Formatter is a free, two-way playground for PHP date formatting. In PHP you turn a date into a string with date() or DateTime::format(), using single-character tokens such as Y for the four-digit year, m for the month, and H:i:s for the time. Remembering every token is tedious — this tool lets you experiment and see the exact output instantly, the same value PHP would return on the server.

It also works in reverse. Paste an example like 00:00:00 and the detector reports the matching format string H:i:s, ready to drop into DateTime::createFromFormat(). That makes it just as useful for parsing dates as for formatting them. Everything runs in your browser — nothing is sent to a server.

How to Use PHP DateTime Formatter

Format a date

  1. Pick a date and time, or press Now.
  2. Type a format string or click a common-format chip.
  3. Read the live output and the per-token breakdown.
  4. Copy the ready-to-paste PHP snippet.

Detect a format

  1. Switch to Detect format.
  2. Paste an example value such as a date or time.
  3. Review every matching PHP format string.
  4. Press Use to load it into format mode, or copy it.

Tip: to print a letter that is also a format character, escape it with a backslash. For example, \Y\e\a\r Y outputs Year 2024.

FAQ

What is the difference between format and detect mode?

Format mode is the classic direction: you pick a date and a PHP format string (like Y-m-d H:i:s) and instantly see the output, the same result PHP returns from DateTime::format() or date(). Detect mode is the reverse: you paste an example such as 00:00:00 and the tool tells you the matching format string is H:i:s.

Does this match PHP exactly?

The format characters follow the official PHP date() / DateTime::format() reference. All date and time tokens (Y, m, d, H, i, s, and so on) are computed in UTC so the output is deterministic. Timezone tokens (O, P, T, e, Z, I) therefore report UTC values.

Why does an example return more than one format?

Some inputs are genuinely ambiguous. 01/02/2024 could be d/m/Y (2 January) or m/d/Y (1 February), and 13:45 matches both H:i and G:i. The detector shows every pattern that reproduces your example exactly so you can choose the right one.

How do I output a literal letter that is also a format character?

Escape it with a backslash. For example \Y\e\a\r Y prints "Year 2024" — each backslash tells PHP to treat the next character as a literal instead of a format token.

How do I parse a string into a date in PHP?

Use DateTime::createFromFormat($format, $string). Detect mode builds that call for you — copy the format it finds and pass it together with your input string.