SyntaxStudy
Sign Up
Python Beginner 3 min read

Python datetime Module

datetime Module

The datetime module provides classes for working with dates, times, and intervals: date, time, datetime, and timedelta.

Example
from datetime import date, time, datetime, timedelta

today = date.today()
now   = datetime.now()
specific = datetime(2024, 6, 15, 14, 30, 0)
print(today, now, specific)
Pro Tip

Always use datetime.now(tz=timezone.utc) in production to avoid timezone-ambiguous naive datetimes.