Using Python datetime to Work With Dates and Times
Have you ever wondered about working with dates and times in Python? In this tutorial, you'll learn all about the built-in Python datetime library. You'll also learn about how to manage time zones and daylight saving time, and how to do accurate arithmetic on dates and times.
Watch Now
This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding:
Using Python's datetime Module – Real Python
Have you ever wondered about working with dates and times in Python? In this video course, you'll learn all about the built-in Python datetime library. You'll also learn about how to manage time zones and daylight saving time, and how to do accurate arithmetic on dates and times.
Working with dates and times is one of the biggest challenges in programming. Between dealing with time zones, daylight saving time, and different written date formats, it can be tough to keep track of which days and times you’re referencing. Fortunately, the built-in Python datetime module can help you manage the complex nature of dates and times.
In this tutorial, you’ll learn
Why programming with dates and times is such a challenge
Which functions are available in the Python datetime module
How to print or read a date and time in a specific format
How to do arithmetic with dates and times
Plus, you’re going to develop a neat application to count down the time remaining until the next PyCon US!
In this tutorial, you learned about programming with dates and times and why it often leads to errors and confusion. You also learned about the Python datetime and dateutil modules as well as how to work with time zones in your code.
Now you can
Store dates in a good, future-proof format in your programs
Create Python datetime instances with formatted strings
Add time zone information to datetime instances with dateutil
Perform arithmetic operations with datetime instances using relativedelta
In the end, you created a script that counts down the time remaining until the next PyCon US so you can get excited for the biggest Python gathering around. Dates and times can be tricky, but with these Python tools in your arsenal, you’re ready to tackle the toughest problems!
Watch Now
This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding:
Using Python's datetime Module – Real Python
Have you ever wondered about working with dates and times in Python? In this video course, you'll learn all about the built-in Python datetime library. You'll also learn about how to manage time zones and daylight saving time, and how to do accurate arithmetic on dates and times.