Using Python's datetime Module (Overview)
Python has several different modules to deal with dates and times. This course concentrates on the primary one,datetime. Dates and times are messy things! Shifts due to daylight savings time and time zones complicate any computing with dates and times.
In this course, you’ll tackle that messiness and learn:
- How to use the
datetimemodule - What the
zoneinfomodule does and how to use it - How tocalculate the difference between two
datetimeobjects
00:00Welcome to Using Python’sdatetime.My name is Christopher, and I will be your guide.This course gives an introduction to the messy world of managing dates and timesin software. As the title implies, it primarily focuses on Python’sdatetimemodule, but also shows some other things along the way.
00:19In this course, you will learn about how messy dates,times, and time zones are, thedatetimemodule, time zones in Python,and how to do date and time math. Codein this course was tested using Python 3.10.
00:36Time zone handling changed significantly in Python 3.9when things previously managed by third-party libraries were brought into thestandard library.The changes were significant enough that they were backported to olderversions. If you’re using something prior to Python 3.9,I’ll point you at the backports when I get there.
00:56Python has three main modules included as part of the standard library fordealing with dates and times. The main one you probably want to use isdatetime,which also includes tools for date objects, timeobjects, and time deltas,although this one’s a bit rudimentary. Dates and times are messy things.
01:16There are loads of formats out there. As a Canadian,I can tell you that I get bit by this all the time.Our American neighbors use a different short form when they write dates.
01:25The difference between day-month-year versus month-day-year can be unclear up until the thirteenth of the month.As a programmer, I try to insist on year-month-day,the international standard, but standard or not,it isn’t always used. Time zones can also cause craziness.
01:44There are more times zones in the world than the twenty-four hours in the clock.That right there tells you something. Not to keep bringing up the Canadian thing,but it is another good example of the mess. Canada has six times zones,one of which, Newfoundland Standard Time, has a half-hour difference from itsnearest neighbor. Combine that with the problem of daylight savings time,which is also messy.
02:05One of our provinces, Saskatchewan, doesn’t follow daylight savings.So in the winter,it aligns with Central Standard Time and has the same time as its neighbor tothe east, Manitoba, while in the summer,it aligns with its neighbor on the other side, Alberta,as it syncs with Mountain Standard Time.
02:24Take off, eh, there’s no doubt about it: date and times are messy.
02:29Now that I’ve slagged my fellow Canadians, next up I’ll dive further into all thecomplications of dates and times.
Course Contents

