Skip to content

Learn: Dates and times

Three short tutorials that take you from the basic datetime types through parsing strings into them and out to time zone handling. Each one is a Jupyter notebook — read it in the browser, and edit and run any code cell directly on the page.

The tutorials build on each other, so working through them in order is the fastest path. Each takes roughly fifteen to twenty minutes.

The sequence

  1. Datetime basicsdate, time, datetime, and timedelta — creation, arithmetic, and comparison.
  2. Parsing and formattingstrptime, strftime, ISO 8601, and fromisoformat.
  3. Time zones with zoneinfo — aware versus naive datetimes, UTC, DST, and cross-zone arithmetic.

Before you start

You don't need much beyond basic Python — variables, if, and print. The notebooks use small amounts of string formatting from the string processing guide, but you can follow along without it.

You don't need Python installed locally — every tutorial runs in your browser. If you'd rather run them on your own machine, each notebook has a download button in the top-right corner.