- Home
- 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.
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 | ||
|---|---|---|
| d | Day of the month, 2 digits with leading zeros (01 to 31) | 26 |
| D | Day of the week, three letters (Mon to Sun) | Mon |
| j | Day of the month without leading zeros (1 to 31) | 26 |
| l | Full day of the week (Sunday to Saturday) | Monday |
| N | ISO 8601 day of the week, 1 (Monday) to 7 (Sunday) | 1 |
| S | English ordinal suffix for the day: st, nd, rd or th. Works well with j | th |
| w | Day of the week, 0 (Sunday) to 6 (Saturday) | 1 |
| z | Day of the year, starting from 0 (0 to 365) | 298 |
| Week | ||
|---|---|---|
| W | ISO 8601 week number of the year, weeks start on Monday | 44 |
| Month | ||
|---|---|---|
| F | Full month name (January to December) | October |
| m | Month with leading zeros (01 to 12) | 10 |
| M | Month, three letters (Jan to Dec) | Oct |
| n | Month without leading zeros (1 to 12) | 10 |
| t | Number of days in the month (28 to 31) | 31 |
| Year | ||
|---|---|---|
| L | Leap year: 1 if it is, 0 otherwise | 0 |
| o | ISO 8601 week-numbering year, matches W | 2026 |
| X | Expanded year with sign, at least 4 digits (PHP 8.2+) | +2026 |
| x | Expanded year if needed, otherwise like Y (PHP 8.2+) | 2026 |
| Y | Full year, at least 4 digits | 2026 |
| y | Two-digit year | 26 |
| Time | ||
|---|---|---|
| a | Lowercase am or pm | pm |
| A | Uppercase AM or PM | PM |
| B | Swatch Internet time (000 to 999) | 628 |
| g | 12-hour hour without leading zeros (1 to 12) | 2 |
| G | 24-hour hour without leading zeros (0 to 23) | 14 |
| h | 12-hour hour with leading zeros (01 to 12) | 02 |
| H | 24-hour hour with leading zeros (00 to 23) | 14 |
| i | Minutes with leading zeros (00 to 59) | 05 |
| s | Seconds with leading zeros (00 to 59) | 09 |
| u | Microseconds. date() always prints 000000; DateTime::format() prints real values | 000000 |
| v | Milliseconds. date() always prints 000 | 000 |
| Time zone | ||
|---|---|---|
| e | Time zone identifier, e.g. UTC or Europe/Berlin | UTC |
| I | Daylight saving time: 1 if in effect, 0 otherwise | 0 |
| O | Difference to UTC without colon, e.g. +0200 | +0000 |
| P | Difference to UTC with colon, e.g. +02:00 | +00:00 |
| p | Like P, but Z for +00:00 (PHP 8.0+) | Z |
| T | Time zone abbreviation, e.g. UTC, EST, CEST | UTC |
| Z | Offset from UTC in seconds (-43200 to 50400) | 0 |
| Full date/time | ||
|---|---|---|
| c | ISO 8601 date, e.g. 2026-10-26T14:05:09+00:00 | 2026-10-26T14:05:09+00:00 |
| r | RFC 2822 date, e.g. Mon, 26 Oct 2026 14:05:09 +0000 | Mon, 26 Oct 2026 14:05:09 +0000 |
| U | Seconds since the Unix epoch (January 1, 1970 UTC) | 1793023509 |
Common PHP date formats
| Format | Result | Use |
|---|---|---|
Y-m-d H:i:s | 2026-10-26 14:05:09 | MySQL DATETIME |
Y-m-d | 2026-10-26 | ISO date |
c | 2026-10-26T14:05:09+00:00 | ISO 8601 |
D, d M Y H:i:s \G\M\T | Mon, 26 Oct 2026 14:05:09 GMT | HTTP header |
l, F jS, Y | Monday, October 26th, 2026 | Long US |
d/m/Y | 26/10/2026 | Day first |
m/d/Y | 10/26/2026 | Month first |
g:i A | 2:05 PM | 12-hour time |
U | 1793023509 | Unix 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
mandi:mis the month,iis minutes.Y-m-d H:mis a classic bug that prints the month where minutes should be.handH: lowercase is the 12-hour clock, so pair it withA. Uppercase is 24-hour.Dandd: uppercase is the weekday name, lowercase is the day number.S: only makes sense right afterj, as injSfor “26th”.WwithY: useoinstead ofYnext to the ISO week number.- Localised names:
date()always prints English names. For other languages, useIntlDateFormatterfrom the intl extension.
More PHP tools
PHP Version Checker
Find the PHP version of any website, or which versions your code runs on.
PHP Sandbox
Write and run PHP 7.4 to 8.5 in your browser. Nothing to install.
PHP Syntax Checker
Find parse errors with the exact line, checked by the real PHP parser.
PHP EOL Dates
Support and end-of-life dates for every PHP version, with countdowns.
Bcrypt Generator
Hash and verify passwords in the format PHP's password_hash() uses.
phpinfo() Analyzer
Paste phpinfo() output and see risky settings and outdated versions.
PHP Formatter
Beautify PHP code to the PSR-12 style in one click.
PHP Regex Tester
Test preg_match, preg_replace and preg_split with real PHP PCRE.
PHP Unserialize
Turn serialized PHP data into a readable tree, JSON or print_r.
JSON to PHP Array
Convert JSON to a PHP array and PHP arrays back to JSON.
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.