#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
⚡ FREE · CHECKED AGAINST PYTHON

strftime Format Builder: Get Your Python Date Format Right First Time

Type a format like %d-%m-%Y and see exactly what Python prints for your date.

  • 📅 27 directives with values
  • 🇮🇳 Indian date presets
  • 🐍 Ready Python code

How to use the Python strftime Date Format Builder

  1. 1. Write a formatOr pick a preset such as DD-MM-YYYY.
  2. 2. Pick a date and timeAdd microseconds or a time zone if you use %f, %z or %Z.
  3. 3. CopyCopy the formatted text or the Python code, which includes strptime to read it back.

The directives you'll use most

  • %d day 01–31, %m month 01–12, %Y four-digit year, %y two-digit year.
  • %B full month name and %b short name; %A and %a for the weekday.
  • %H 24-hour clock, %I 12-hour clock with %p for AM/PM, %M minutes, %S seconds and %f microseconds.
  • %j day of the year, %U/%W week numbers, and %V/%G for ISO weeks.
  • %z and %Z for 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 → date

The 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.

More free tools

See all free tools