Python datetime Module The datetime module provides classes for manipulating dates, times, and time intervals. It is the standard tool for any date and time operations in Python, from simple date formatting to complex timezone-aware calculations. Use Cases: - Getting the current date and time - Parsing date strings into datetime objects - Formatting dates for display or serialization - Calculating differences between dates (timedelta) - Working with timezones using timezone or third-party libraries like zoneinfo Example 1: Parsing and formatting dates from datetime import datetime date_str = "2025-03-15 14:30:00" dt = datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S") print(dt.strftime("%B %d, %Y at %I:%M %p")) # March 15, 2025 at 02:30 PM Example 2: Calculating date differences from datetime import datetime, timedelta today = datetime.now() deadline = datetime(2025, 12, 31) remaining = deadline - today print(f"Days until deadline: {remaining.days}") next_week = today + timedelta(weeks=1) print(f"Next week: {next_week.strftime('%Y-%m-%d')}") Key classes include date (calendar date only), time (time of day only), datetime (combined date and time), timedelta (duration between two dates), and timezone (fixed UTC offset). For full timezone support, Python 3.9+ includes the zoneinfo module as a modern replacement for pytz.