Date Format Cheat Sheet

Every date format code for Python strftime, Java, C#, date-fns, Moment, PHP, MySQL and PostgreSQL, with examples and common formats.

Runs in your browser. Nothing is uploaded.

Examples show Wednesday 4 March 2026, 15:07:09.123456 in India (UTC+05:30, IST).

dt.strftime("%Y-%m-%d")
Python (strftime) date format codes
CodeMeaningExample
%YYear, 4 digits2026
%yYear, 2 digits26
%-mMonth number (1–12)Linux and macOS only; on Windows use # instead of -.3
%mMonth number, 2 digits (01–12)03
%bMonth name, short (Mar)Mar
%BMonth name, full (March)March
%-dDay of the month (1–31)Linux and macOS only; on Windows use # instead of -.4
%dDay of the month, 2 digits (01–31)04
%jDay of the year, 3 digits (001–366)063
%aWeekday, short (Wed)Wed
%AWeekday, full (Wednesday)Wednesday
%uISO weekday number (1 = Monday … 7 = Sunday)3
%VISO week number, 2 digits (01–53)10
%GISO week-numbering year2026
%-HHour, 24-hour clock (0–23)Linux and macOS only; on Windows use # instead of -.15
%HHour, 24-hour clock, 2 digits (00–23)15
%-IHour, 12-hour clock (1–12)Linux and macOS only; on Windows use # instead of -.3
%IHour, 12-hour clock, 2 digits (01–12)03
%-MMinute (0–59)Linux and macOS only; on Windows use # instead of -.7
%MMinute, 2 digits (00–59)07
%-SSecond (0–59)Linux and macOS only; on Windows use # instead of -.9
%SSecond, 2 digits (00–59)09
%fMicroseconds, 6 digits123456
%pAM / PMPM
%:zUTC offset with colon (+05:30)Python 3.12 and later.+05:30
%zUTC offset without colon (+0530)+0530
%ZTime zone abbreviation (IST)Empty for naive datetimes.IST
%sUnix timestamp, secondsNot official and platform-dependent; prefer int(dt.timestamp()).1772617029

No code in Python (strftime): milliseconds, 3 digits; utc offset, z for zero (z, +05:30); unix timestamp, milliseconds.

Common formats in Python (strftime)

Common date formats in Python (strftime)
FormatPatternExample
ISO 8601 date%Y-%m-%d2026-03-04
ISO 8601 date and time with offset%Y-%m-%dT%H:%M:%S%:z2026-03-04T15:07:09+05:30
SQL datetime%Y-%m-%d %H:%M:%S2026-03-04 15:07:09
Day first (Europe, Asia, Latin America)%d/%m/%Y04/03/2026
Month first (United States)%m/%d/%Y03/04/2026
Written out%-d %B %Y4 March 2026
Weekday and date%A, %-d %B %YWednesday, 4 March 2026
12-hour time%-I:%M %p3:07 PM
RFC 2822 (email, RSS)%a, %d %b %Y %H:%M:%S %zWed, 04 Mar 2026 15:07:09 +0530
Timestamp for file names%Y%m%d_%H%M%S20260304_150709

How to use the Date Format Cheat Sheet

  1. Choose your Language, for example Python (strftime), Java or MySQL.
  2. Scan the table for the part of the date you need, or type a word like month or a code like %d under Find a code.
  3. Check the Example column to see exactly what the code prints for 4 March 2026, 15:07:09.
  4. Copy a ready-made pattern from Common formats, such as ISO 8601 or RFC 2822.

Every date code in one place

Date format codes are easy to forget and easy to confuse between languages. This cheat sheet lists the codes for eight common ones: Python’s strftime, Java’s DateTimeFormatter (the same letters work for SimpleDateFormat in most cases), C# / .NET custom format strings, the JavaScript libraries date-fns, Moment.js and Day.js, PHP’s date(), MySQL’s DATE_FORMAT and PostgreSQL’s (and Oracle’s) TO_CHAR.

Every table shows the same sample moment, Wednesday 4 March 2026 at 15:07:09.123456 in India (UTC+05:30), so you can compare codes side by side: a single-digit day and month show whether a code pads with zeros, and the afternoon time shows 24-hour against 12-hour codes.

Common formats, ready to copy

Under each table you’ll find patterns for the formats people need most: ISO 8601 dates and timestamps for APIs, the SQL datetime format, day-first and US month-first dates, written-out dates, 12-hour times, RFC 2822 for email and RSS, and a compact timestamp for file names. A line of code at the top shows how the pattern is used in that language.

Pitfalls to watch for

  • Minutes or month: mm / MM in Java, C#, date-fns and Moment; %M / %m in Python; %i / %m in MySQL.
  • Week year: YYYY in Java and date-fns is the ISO week-based year. Use yyyy.
  • Day of year: DD and D in Java and date-fns are the day of the year, not the month.
  • Padding: PostgreSQL pads Month and Day with spaces unless you add FM.
  • Platform codes: Python’s %-d works on Linux and macOS; Windows uses %#d.

To try a pattern on any date, or convert it to another language, use the Date Pattern Tester.

Frequently asked questions

What is the difference between %m and %M in Python?

%m is the month as two digits (03) and %M is the minutes (07). In MySQL it is different again: %M is the month name and minutes are %i.

Why do Java and C# use yyyy but Moment uses YYYY?

Each library chose its own letters. In Java and date-fns YYYY is the week-based year, which is wrong for normal dates, while in Moment and Day.js YYYY is the normal year. Check the table for your language.

How do I print literal text such as the T in ISO dates?

Quote it. Java, date-fns and .NET use 'T', Moment uses [T], PHP uses \T and PostgreSQL uses "T". Python and MySQL print letters as they are, and need %% for a percent sign.

Does JavaScript's Intl.DateTimeFormat use these codes?

No. Intl.DateTimeFormat takes options such as { year: 'numeric', month: 'long' } and orders them by locale. Use date-fns or Day.js when you need an exact pattern.

Why are some codes missing for a language?

Not every language can print every field. Those gaps are listed under each table, and the Date Pattern Tester shows them when you translate a pattern.

Tutorials

Tutorial · 5 min · beginner

How to format dates in Python with strftime

Use the strftime cheat sheet to build Python date formats for ISO 8601, day-first dates, month names and 12-hour times, with examples for each code.