How to use the Python strftime Date Format Builder
- 1. Write a formatOr pick a preset such as DD-MM-YYYY.
- 2. Pick a date and timeAdd microseconds or a time zone if you use %f, %z or %Z.
- 3. CopyCopy the formatted text or the Python code, which includes strptime to read it back.
The directives you'll use most
%dday 01–31,%mmonth 01–12,%Yfour-digit year,%ytwo-digit year.%Bfull month name and%bshort name;%Aand%afor the weekday.%H24-hour clock,%I12-hour clock with%pfor AM/PM,%Mminutes,%Sseconds and%fmicroseconds.%jday of the year,%U/%Wweek numbers, and%V/%Gfor ISO weeks.%zand%Zfor the UTC offset and zone name; these are empty for a naive datetime with no time zone.
A common mistake is mixing up %m (month) and %M (minute). Another is using %-d for a day without a leading zero: it works on Linux and macOS but fails on Windows, which uses %#d. The tool warns you about both kinds of non-portable code.
Worked example
For 15 August 2026 at 14:30:05, the format %d %b %Y, %I:%M %p gives 15 Aug 2026, 02:30 PM. The presets show other common styles: %d-%m-%Y → 15-08-2026, %Y-%m-%d %H:%M:%S → 2026-08-15 14:30:05, and %A, %d %B %Y → Saturday, 15 August 2026. The day of the year (%j) is 227.
The code box gives you both directions:
dt.strftime("%d %b %Y, %I:%M %p") # date → text
datetime.strptime("15 Aug 2026, 02:30 PM", "%d %b %Y, %I:%M %p") # text → dateThe formatting follows Python's rules in the default English (C) locale. We checked every directive against Python 3's own strftime on hundreds of dates. Month and day names change only if your program sets a different locale.
Frequently asked questions
What is the difference between strftime and strptime?
strftime formats a datetime as text (f for format). strptime parses text into a datetime (p for parse), using the same codes.
How do I show the day without a leading zero?
Use f"{dt.day}" or dt.strftime("%d").lstrip("0"). %-d works only on Linux and macOS.
Do pandas and Django use the same codes?
pandas to_datetime(format=…) and .dt.strftime use the same codes. Django templates use their own date filter letters.
Do I have to pay for the python strftime date format builder?
No, it is free. Formatting your first date asks for your name and WhatsApp number one time only. Then the python strftime date format builder and all other Uncodemy tools stay open for you with no form.