Articles
Published · November 18, 2026

strftime Format Codes: Date Stamps for File Names and Notes

strftime format codes are short %-codes that turn a date into text. Learn the ones that matter for file names and note headers, and which to avoid.

Also in: Español中文हिन्दी

Quick answer

strftime format codes are short sequences that start with % and turn a date into text. %Y-%m-%d gives 2026-11-18, and %F is a shorthand for the same thing. Put them in a format string, and the program swaps each code for the matching part of the date. Everything else in the string is copied as written.

The same idea shows up in C, in the shell's date command, in Python and in many templates. Learn about a dozen codes and your file names and note stamps will sort correctly.

notes-%F-%H%M%S.md   ->   notes-2026-11-18-143005.md

How strftime format codes work

The strftime(3) manual page describes the rule: each conversion specification starts with % and ends with a specifier character. Ordinary characters are copied verbatim. To print a literal percent sign, write %%.

Here are the codes you will use most:

| Code | Meaning | Example | |------|---------|---------| | %Y | Year with century | 2026 | | %m | Month, 01 to 12 | 11 | | %d | Day of month, 01 to 31 | 18 | | %e | Day of month, space-padded | 8 (with a leading space) | | %H | Hour, 24-hour clock, 00 to 23 | 14 | | %I | Hour, 12-hour clock, 01 to 12 | 02 | | %M | Minute, 00 to 59 | 30 | | %S | Second, 00 to 60 | 05 | | %p | AM or PM | PM | | %j | Day of the year, 001 to 366 | 322 |

Two details trip people up. %d pads the day with a zero, while %e replaces that zero with a space, so %e is a poor choice for file names. And %S can reach 60 to allow for the occasional leap second.

The man page also defines a few shortcuts. %F is equivalent to %Y-%m-%d, and the page calls it the ISO 8601 date format. %T is equivalent to %H:%M:%S, and %R is %H:%M.

Sortable file names with %F and %T

ISO 8601 orders date values from the largest unit to the smallest: year, month, day, hour, minute, second. Each value has a fixed number of digits, padded with leading zeros. That is why dates in this order sort naturally in a file system, with no special sorting rule needed. Our piece on date-first file names shows the effect in a folder listing.

For a daily note, %F is enough:

%F.md           ->   2026-11-18.md
%F-meeting.md   ->   2026-11-18-meeting.md

Need the time too? Be careful with %T. It produces colons (14:30:05), and colons are one of the characters that cause trouble across Mac, Windows and Linux file systems. See characters to avoid in file names for the full list. Spell out the time with %H%M%S instead:

%F-%H%M%S.md   ->   2026-11-18-143005.md

ISO 8601 also defines a compact form without separators, such as 20090106. The standard itself notes that the basic format should be avoided in plain text, so the hyphenated %F is easier to read.

Week numbers: %V and %G

If you keep weekly notes, %V gives the ISO 8601 week number, from 01 to 53, where week 1 is the first week with at least four days in the new year. Pair it with %G, the ISO week-based year, not %Y. Near the end of December and the start of January, the two can disagree: if the ISO week belongs to the neighboring year, %G uses that year. A name like %G-W%V.md stays correct across the boundary. More on that in ISO week numbers for weekly notes.

Codes to avoid or handle with care

  • `%D` means %m/%d/%y. The man page itself warns that in an international context it is ambiguous, because many countries write %d/%m/%y. Skip it.
  • `%a`, `%A`, `%b`, `%B` print weekday and month names according to the current locale. The same format string can produce Nov on one machine and a different word on another.
  • `%c` is the locale's preferred date and time representation, so its output varies by locale too.
  • `%z` and `%Z` give the UTC offset (-0400) and the time zone name. Both contain characters you may not want in a file name.
  • `%s` is the number of seconds since 1970-01-01 00:00:00 UTC. It is unique and sorts well, but nobody can read it at a glance.

Using the codes in the shell and Python

In a shell, date takes the same codes after a plus sign:

touch "$(date +%F)-ideas.md"

If you run that from a scheduled job, our guide to crontab syntax covers one catch: a bare % has its own meaning there.

Python's datetime objects have a strftime() method, and the datetime documentation lists the codes it supports, including %f for microseconds and %:z for an offset written as -04:00. It also warns that the full set of codes varies across platforms, because Python calls the platform's C library strftime(). Stick to the common codes above when a script has to run on more than one system.

from datetime import datetime
print(datetime.now().strftime("%F-%H%M%S"))

How Carets fits in

Format codes only help if the files they create are easy to open later. Carets is a fast, native notes and code editor for iPhone, iPad and Mac. It works with Markdown and plain text, so a note named 2026-11-18-143005.md is just a file you own. Files, projects and tags keep date-stamped notes organized, and syntax highlighting makes the shell and Python snippets above readable when you save them as a cheat sheet. Your files stay plain text, so they stay portable.

Get Carets on the App Store for iPhone, iPad and Mac.

Frequently Asked Questions

What does %F mean in strftime?

%F is shorthand for %Y-%m-%d, the ISO 8601 date format. On 18 November 2026 it produces 2026-11-18.

What is the difference between %d and %e?

Both give the day of the month. %d pads with a leading zero (07), while %e pads with a space instead. Use %d in file names.

Why does my date format differ between machines?

Weekday and month names follow the current locale, and Python passes its codes to the platform's C library, so the supported set can vary. Numeric codes such as %Y, %m and %d stay consistent.