Python Module: Datetime
Posted: Jul 14, 2025
Updated: Jul 28, 2025
Posted: Jul 14, 2025
Updated: Jul 28, 2025
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.
strftime()
Formatstrftime()
stands for “string format time”, and it’s used to convert a datetime
object into a readable string.
Code | Meaning | Example Output |
---|---|---|
%Y | Year (4 digits) | 1999 |
%m | Month (01–12) | 04 (April) |
%d | Day of month (01–31) | 19 |
%A | Full weekday name | Monday |
%a | Abbreviated weekday | Mon |
%B | Full month name | April |
%b | Abbreviated month name | Apr |
%H | Hour (00–23) | 07 |
%I | Hour (01–12) | 07 (with AM/PM) |
%p | AM or PM | AM |
%M | Minute (00–59) | 00 |
%S | Second (00–59) | 00 |