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
Output
$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 formatExample values are computed from the date currently selected above.
| d | Day of the month, 2 digits with leading zeros (01–31) | 15 |
| j | Day of the month without leading zeros (1–31) | 15 |
| D | Day name, three letters (Mon–Sun) | Mon |
| l | Full day name (Sunday–Saturday) | Monday |
| N | ISO day of week (1 = Monday … 7 = Sunday) | 1 |
| w | Day of week, numeric (0 = Sunday … 6 = Saturday) | 1 |
| S | English ordinal suffix (st, nd, rd, th) | th |
| z | Day of the year, zero-indexed (0–365) | 14 |
| W | ISO-8601 week number of the year | 03 |
| m | Month, 2 digits with leading zeros (01–12) | 01 |
| n | Month without leading zeros (1–12) | 1 |
| M | Month name, three letters (Jan–Dec) | Jan |
| F | Full month name (January–December) | January |
| t | Number of days in the given month (28–31) | 31 |
| Y | Full numeric year, 4 digits (e.g. 2024) | 2024 |
| y | Two-digit year (e.g. 24) | 24 |
| L | Leap year (1 if leap, 0 otherwise) | 1 |
| o | ISO-8601 week-numbering year | 2024 |
| H | 24-hour format with leading zeros (00–23) | 13 |
| G | 24-hour format without leading zeros (0–23) | 13 |
| h | 12-hour format with leading zeros (01–12) | 01 |
| g | 12-hour format without leading zeros (1–12) | 1 |
| i | Minutes with leading zeros (00–59) | 45 |
| s | Seconds with leading zeros (00–59) | 30 |
| A | Uppercase AM or PM | PM |
| a | Lowercase am or pm | pm |
| v | Milliseconds (e.g. 654) | 000 |
| u | Microseconds (e.g. 654000) | 000000 |
| B | Swatch Internet time (000–999) | 614 |
| e | Timezone identifier (UTC in this tool) | UTC |
| T | Timezone abbreviation (UTC in this tool) | UTC |
| O | Offset to GMT, no colon (e.g. +0000) | +0000 |
| P | Offset to GMT, with colon (e.g. +00:00) | +00:00 |
| Z | Timezone offset in seconds | 0 |
| I | Daylight saving time (1 or 0) | 0 |
| c | ISO-8601 date (2004-02-12T15:19:21+00:00) | 2024-01-15T13:45:30+00:00 |
| r | RFC 2822/5322 formatted date | Mon, 15 Jan 2024 13:45:30 +0000 |
| U | Seconds since the Unix Epoch | 1705326330 |
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
- Pick a date and time, or press Now.
- Type a format string or click a common-format chip.
- Read the live output and the per-token breakdown.
- Copy the ready-to-paste PHP snippet.
Detect a format
- Switch to Detect format.
- Paste an example value such as a date or time.
- Review every matching PHP format string.
- 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.