
Each language spells the same part of a date its own way, so switching languages means looking codes up again. Type the code you already know, such as %m or 2006, into the date code table, and its row shows the equivalent in the other four.
Date format cheat sheet for Python, PHP, Go, JavaScript and Excel
Date code table: five groups (44 rows)
Each row of the date code table is one part of a date or time, named in the first column and usually shown with an example output. The next five columns hold the JavaScript, Python, Go, PHP and Excel ways to produce it.
You can search by a code (%Y, 2006, yyyy) or by the name of the part (month, weekday). Searching by a code also translates a format string from one language to another: find its row and read across. What you type stays in your browser and is not sent anywhere.
A dash means the official docs give no single code or option for that part in that environment. For example, the documented strftime codes include no month without a leading zero, so that row shows a dash in the Python column.
Python strftime and PHP date format codes side by side
In Python you pass a format string to strftime on a datetime, and in PHP to the date function or to format on a DateTime. In both, any character that is not a code is printed as is.
Python codes all start with %: %Y-%m-%d for the date and %H:%M:%S for the time. PHP codes are single letters without %, so the same date and time format is Y-m-d H:i:s.
Because many letters are codes in PHP, put a backslash before a code letter you want printed literally. Python only treats % pairs as codes, so plain letters need no escaping.
from datetime import datetime
datetime.now().strftime("%Y-%m-%d %H:%M:%S") # 2026-09-26 15:04:05
<?php
echo date("Y-m-d H:i:s"); // 2026-09-26 15:04:05
JavaScript date format with Intl.DateTimeFormat options
JavaScript has no format codes like %Y or yyyy. Instead, you give Intl.DateTimeFormat an option for each part you want to show. The JavaScript column of the date code table lists those options.
Year, day, hour, minute and second take "numeric" or "2-digit". Month also takes "long" (September), "short" (Sep) and "narrow" (S). Fractions of a second use fractionalSecondDigits, which takes a number from 1 to 3.
new Intl.DateTimeFormat("en-US", {
year: "numeric", month: "2-digit", day: "2-digit",
hour: "2-digit", minute: "2-digit", hourCycle: "h23",
}).format(new Date()); // 09/26/2026, 15:04
The order of the parts and the separators come from the locale, the first argument that names a language and region. With the same options, "en-US" gives month/day/year and "ja-JP" gives year/month/day. To choose the separators yourself, build the string by hand as shown in Format a date as yyyy-mm-dd or yyyymmdd in JavaScript.
The number of digits used to represent fractions of a second (any additional digits are truncated). Possible values are from 1 to 3. — from the fractionalSecondDigits optionView official source →
Month or minute: date time format codes that look alike
Month and minute codes by environment
Month and minute both start with M, so they are an easy pair to swap by mistake. Python tells them apart by case, Excel by position, Go by number, and PHP gives the minute its own letter, i.
Excel date format codes: when mm means minutes
In an Excel number format, m and mm can mean either the month or the minute. Excel shows minutes when the code comes right after h or hh, or right before ss. Anywhere else, it shows the month.
In yyyy/mm/dd hh:mm:ss, the first mm sits between the year and the day, so it is the month. The second follows hh, so it is the minute. mm:ss also shows minutes, because the mm comes right before ss.
If you expected minutes and got a month number, look at what sits next to mm. A format made of mm alone always shows the month, even on a cell that holds only a time.
If you need date formulas such as TODAY, EDATE and DATEDIF rather than number formats, Google Sheets functions list: Excel equivalents shows which ones work in both Excel and Google Sheets. Its table can be searched the same way as the one above.
Python strftime %M and PHP date i for minutes
Python's strftime splits month and minute by case. Lowercase %m is the month and uppercase %M is the minute; the second, %S, is uppercase too, so the time reads %H:%M:%S.
PHP's date uses i for minutes. Uppercase M gives the short month name, such as Sep. When you port %H:%M:%S from Python, write H:i:s, not H:M:S.
Other letters change meaning with case as well. In PHP, d is the day and D the short weekday name, and y is the two-digit year and Y the four-digit year, the same pairing as Python's %y and %Y.
The "m" or "mm" code must appear immediately after the "h" or "hh" code or immediately before the "ss" code; otherwise, Excel displays the month instead of minutes. — from the date and time codes sectionView official source →
Go time format uses the 2006-01-02 reference time
Parts of Go's reference time (January 2, 2006, 15:04:05)
Go has no codes such as %Y or yyyy. You write one fixed moment, January 2, 2006 at 15:04:05, in the shape you want the output to take. Go calls it the reference time and stores it in the constant Layout in the time package.
Golang date format: what 2006, 01, 02 and 15:04:05 mean
Written in US order with a UTC offset of -7 hours, the reference time is 01/02 03:04:05PM '06 -0700. Month, day, hour, minute, second, year and offset are numbered 1 to 7 in turn, which makes the layout easy to remember.
2006-01-02 gives year-month-day and 15:04:05 gives hour:minute:second. 01 is the padded month and 1 the unpadded one; the day is 02 or 2, and the hour is 03 or 3 on a 12-hour clock or 15 on a 24-hour clock. Mon is the short weekday name and Monday the full one.
Each number is read by which part of the reference time it matches. If you write 03 meaning the day, Go reads it as the 12-hour hour. Digits inside other numbers are read as parts too: in a fixed year such as 2025, the 2, 02 and 5 are read as the day, the padded day and the second. Copy the numbers straight from the reference time, and add fixed digits after formatting instead.
t := time.Now()
t.Format("2006-01-02 15:04:05") // 2026-09-26 15:04:05
t.Format("Mon, January 2, 2006") // Sat, September 26, 2026
RFC3339 and other Go constants for ISO 8601 format
The time package ships common layouts as constants. One of them, time.RFC3339, is 2006-01-02T15:04:05Z07:00: a T between date and time and a UTC offset at the end, which is the ISO 8601 shape.
Z07:00 prints Z for a UTC time and an offset such as +09:00 otherwise. Plain -07:00 prints +00:00 even for UTC.
For the date alone there is time.DateOnly (2006-01-02), and for the time alone time.TimeOnly (15:04:05). time.DateTime (2006-01-02 15:04:05) separates date and time with a space instead of a T, so it is not the ISO 8601 shape.
The reference time used in these layouts is the specific time stamp: 01/02 03:04:05PM '06 -0700 (January 2, 15:04:05, 2006, in time zone seven hours west of GMT). — from the Constants sectionView official source →
yyyymmdd and ISO 8601 date format in each language
September 26, 2026, 15:04:05 at UTC+09:00 in two formats
These two strings are common in file names and data exchange. Both are also in the "Common formats" group of the date code table.
Format a date as yyyy-mm-dd or yyyymmdd in JavaScript
yyyymmdd is a four-digit year followed by a two-digit month and day with no separators, so September 26, 2026 becomes 20260926. Because larger numbers are later dates, file names that start with it sort by date when sorted by name. Python writes it as %Y%m%d, PHP as Ymd, Go as 20060102 and Excel as yyyymmdd.
Intl.DateTimeFormat has no option to choose the separators, so in JavaScript you take the year, month and day from the Date and join them. Because getMonth() counts January as 0, add 1 before padding it to two digits.
const d = new Date();
const pad = (n) => String(n).padStart(2, "0");
const ymd = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`; // 2026-09-26
const yyyymmdd = ymd.replaceAll("-", ""); // 20260926
Japanese documents sometimes need the year in the Japanese era system instead. Reiwa year to Western year, with a table lists each Reiwa year next to its Western year.
ISO 8601 timestamps with milliseconds and a UTC offset
An ISO 8601 timestamp joins the date and time with a T and ends with the offset from UTC (Coordinated Universal Time). For Japan it looks like 2026-09-26T15:04:05+09:00.
| Environment | ISO 8601 with UTC offset |
|---|---|
| Python | %Y-%m-%dT%H:%M:%S%:z |
| Go | time.RFC3339 |
| PHP | c |
Python's %z gives the offset without a colon (+0900); %:z, added in Python 3.12, gives +09:00. In PHP, the single letter c prints the whole ISO 8601 timestamp. O gives the offset without a colon and P with one, and p, added in PHP 8.0.0, prints Z for UTC.
For milliseconds, PHP uses v and Go uses .000. In Go the number of zeros after the period sets the digits, and writing nines instead, as in .999, drops any trailing zeros.
Python's %f is always six digits of microseconds. JavaScript sets the digits with fractionalSecondDigits, and Excel adds a period and zeros after the seconds, as in ss.00.
ISO 8601 date. Only compatible with the non-expanded format (up to year 9999). — from the entry for the format character cView official source →
FAQ
- How do I remove leading zeros from a month or day?
- In PHP, use n for the month and j for the day. In Go, write 1 and 2 instead of 01 and 02. In Excel, use m and d. In JavaScript, pass "numeric" for month and day. Python's documented strftime codes have no unpadded month or day; anything beyond that list depends on the platform's C library, so the same code may not work on every system.
- Why does Go use 2006-01-02 as its date format?
- A Go layout is the fixed reference time, January 2, 2006 at 15:04:05, seven hours west of GMT, written the way you want the output to look, and 2006-01-02 is its date in year-month-day order. Written in US order it reads 01/02 03:04:05PM '06 -0700, so month, day, hour, minute, second, year and offset are 1 to 7 in turn.



