0Pricing
Python Academy · Lesson

date, time, datetime

Create and read date objects.

Meet the datetime Module

Python's datetime module lives in the standard library and gives you tools to work with calendar dates and clock times.

  • date stores a year, month, and day.
  • time stores hours, minutes, seconds, and microseconds.
  • datetime combines both into one object.

Import it with from datetime import date, time, datetime.

from datetime import date, time, datetime
print(date)
print(time)
print(datetime)

Creating a date

Build a date by passing year, month, day as integers. Months and days are 1-based and validated automatically.

from datetime import date
birthday = date(1995, 7, 14)
print(birthday)

All lessons in this course

  1. date, time, datetime
  2. Timedelta and Arithmetic
  3. Formatting and Parsing
  4. Time Zones with zoneinfo
← Back to Python Academy