strftime format codes turn a date and time into text. The same codes work in Python, C, Ruby, and the Linux date command. This cheat sheet lists the common codes with examples, plus ready-made format strings.
Date codes
| Code | Meaning | Example |
|---|---|---|
%Y |
Year, four digits | 2026 |
%y |
Year, two digits | 26 |
%m |
Month, zero-padded | 06 |
%B |
Month name, full | June |
%b |
Month name, short | Jun |
%d |
Day of month, zero-padded | 15 |
%j |
Day of the year | 166 |
%a |
Weekday, short | Mon |
%A |
Weekday, full | Monday |
%w |
Weekday number, Sunday is 0 | 1 |
%u |
Weekday number, Monday is 1 | 1 |
Time codes
| Code | Meaning | Example |
|---|---|---|
%H |
Hour, 24-hour, zero-padded | 14 |
%I |
Hour, 12-hour, zero-padded | 02 |
%p |
AM or PM | PM |
%M |
Minute | 09 |
%S |
Second | 07 |
%f |
Microseconds (Python) | 000000 |
%z |
UTC offset | +0300 |
%Z |
Time zone name | EEST |
Combined and misc
| Code | Meaning | Example |
|---|---|---|
%c |
Full date and time | Mon Jun 15 14:09:07 2026 |
%x |
Date, locale format | 06/15/26 |
%X |
Time, locale format | 14:09:07 |
%s |
Seconds since 1970 (GNU date) | 1781000000 |
%% |
A literal percent sign | % |
Ready-made format strings
| Format | Produces |
|---|---|
%Y-%m-%d |
2026-06-15 (ISO date) |
%Y-%m-%dT%H:%M:%S |
2026-06-15T14:09:07 (ISO 8601) |
%d/%m/%Y |
15/06/2026 (day first) |
%m/%d/%Y |
06/15/2026 (US style) |
%A, %B %d, %Y |
Monday, June 15, 2026 |
%H:%M |
14:09 (24-hour time) |
%I:%M %p |
02:09 PM (12-hour time) |
Frequently Asked Questions
What is strftime?
strftime, short for string format time, is a function that turns a date and time into a text string using percent-code placeholders such as %Y and %m.
Are these codes the same in every language?
The core codes match across Python, C, Ruby, and the Linux date command. A few extras differ, and modern PHP uses the DateTime format method with different letters.
What is the difference between %m and %M?
Lowercase %m is the month (01 to 12). Uppercase %M is the minute (00 to 59). Case matters for every code.
How do I get a 12-hour clock with AM or PM?
Use %I for the 12-hour hour and %p for AM or PM, for example %I:%M %p gives 02:09 PM.
See our free date and time tools for timestamps and conversions.