Current date & time
Get the current date, time, or datetime
Create specific date
Construct a date or datetime from components
From timestamp
Convert Unix timestamp to datetime and back
From ISO format string
Parse ISO 8601 format strings
strftime - format to string
Convert datetime to a formatted string
strptime - parse from string
Parse a string into a datetime object
Format codes cheat sheet
All strftime/strptime format codes
ISO format output
Convert to ISO 8601 string
Create timedelta
Represent a duration (difference between two dates/times)
Date arithmetic
Add/subtract time from dates and datetimes
Timedelta to human-readable
Extract days, hours, minutes from a timedelta
UTC datetime
Create timezone-aware datetime in UTC
zoneinfo - named timezones
Use IANA timezone names (Python 3.9+)
Convert between timezones
Convert a datetime from one timezone to another
List available timezones
Get all valid timezone names
Compare dates
Check if a date is before, after, or equal to another
Extract components
Get year, month, day, hour, minute, etc.
Day of week, week number
Get weekday name and ISO week number
Replace components
Create a new datetime with some fields changed
f-string number formatting
Format numbers with commas, decimals, padding
Percentage & scientific
Format as percentage, scientific notation, or binary/hex
format() and locale
Format numbers with locale-specific separators
Currency formatting
Format money values properly
Basic math functions
abs, round, min, max, pow, divmod
math module essentials
sqrt, log, ceil, floor, pi, e, inf
Trigonometry & radians
sin, cos, tan, degrees/radians conversion
Combinatorics
factorial, comb, perm, gcd, lcm
Float precision gotchas
Why 0.1 + 0.2 != 0.3 and how to handle it
Decimal for precision
Exact decimal arithmetic for money and science
int vs float conversion
Converting between numeric types safely
Age from birthday
Calculate someone's age from their date of birth
Business days / weekdays
Count or iterate over weekdays between two dates
Start/end of month
Get the first and last day of any month
Date range generator
Generate a sequence of dates between two dates
Measure execution time
Time how long code takes to run
Human-readable time ago
Convert a datetime to "2 hours ago" format