A summary/cheatsheet for Python built-in datetime module. This summary covers the core classes and common use cases for working with dates, times, time differences, and formatting in Python.

Common strftime() Format

strftime() stands for “string format time”, and it’s used to convert a datetime object into a readable string.

CodeMeaningExample Output
%YYear (4 digits)1999
%mMonth (01–12)04 (April)
%dDay of month (01–31)19
%AFull weekday nameMonday
%aAbbreviated weekdayMon
%BFull month nameApril
%bAbbreviated month nameApr
%HHour (00–23)07
%IHour (01–12)07 (with AM/PM)
%pAM or PMAM
%MMinute (00–59)00
%SSecond (00–59)00
Back to Writings