A Deep Dive Into Date And Time In Python

preview_player
Показать описание
You can easily get overwhelmed when working with date and time data. There are numerous date and time formats, ISO standards, time zones, and daylight-saving settings. In today’s video, I am taking a deep dive into Python’s built-in datetime package and the available alternatives that can help you quickly deal with this type of data.

🎓 Courses:

👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!

👀 Code reviewers:
- Yoriz
- Ryan Laursen
- James Dooley
- Dale Hagglund

🔖 Chapters:
0:00 Intro
2:00 Unix time
3:03 The year 2038 problem
4:03 UTC
4:44 Using dates and time in Python
7:33 How to deal with Timezones
9:33 Datetime limitations
11:10 Pendulum package
18:16 Final thoughts

#arjancodes #softwaredesign #python

DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!
Рекомендации по теме
Комментарии
Автор

I want to mention that python has an added standard library module `zoneinfo` since 3.9 that can eliminate external dependencies for timezone handling in a lot of cases.

iChrisBirch
Автор

Thanks for the video, Arjan. By the way, I love this 'series' you going through the standard library. Though I am already aware of their features, there is always something to learn or to get used to. By the way, didn't know you normally record your videos a month before you launch them here :)

Side note: I didn't found the link you mentioned at 7:30;

MutleyXIII
Автор

I have a recent fight with timezones. Not fun. You think all timezones are utc +- integer value? Wrong. Nepal has +45 minutes because of mountain alignment I believe. You think every country has one timezone? Wrong! You think every US state follows daylight saving consistently? Wrong! You think every city has one timezone? Wrong! There was an amazing article about misconceptions about timezones, need to find it and link here…

MessLeadingProgramming
Автор

Hi Arjan, I've learned a lot from your videos. Was wondering if you have tried using "#%%" in vscode on your videos so you don't have to change to terminal to show code output? For those who may not know. Once you have the Python extension installed in VSCode, if you add "#%%" on top a code block, you'll be able to either click a button to run that code block, or all blocks below it. The output is shown in a new tab on the right by default. For example:
#%%
print("Hi Friend")

gargolito
Автор

Hey Arjan, thank you very much for your video. I'm following you from the very beginning. There are very few channels who are worth mentioning including yourself and @MathByte Academy. Kudos to you for making us a better programmer and learner every week. Keep doing great work !

saurabhmishra
Автор

Nice Arjan, now I know, when to take out my broetchen in NL time.

But seriously, such a good tool. I didnt catch this feature here, but for those who want to use datetime in a for loop over a period between two dates with a specific interval e.g. every 2 days or every 13h37mins - looping through this using pendulum is a breeze!

hudabdulwahab
Автор

This is interesting, and somewhat of a rabbit hole. I work in the industrial field (product coding). Dealing with dates there is always a challenge, since companies invent new date coding demands all the time. Commonly "Julian" dates are used, so something along "2391349" could mean "day 239 13:49". And there are special needs for encrypting days, dealing with offsets (around jan/feb/mar!), etc etc. Btw, you don't talk too much about the process of going from string->datetime, dealing with dates in random formats. This could be a topic for another video, assuming you have dates as string "23/10/22" or "20221023" or "23. oktober '22", and having to convert to a datetime. This is often asked in fora. Thank you for great content.

havenisse
Автор

Quote from PostgreSQL docs on date/time:

The first century starts at 0001-01-01 00:00:00 AD, although they did not know it at the time. This definition applies to all Gregorian calendar countries. There is no century number 0, you go from -1 century to 1 century. If you disagree with this, please write your complaint to: Pope, Cathedral Saint-Peter of Roma, Vatican.

Автор

Use built-in zoneinfo (Python 3.9+) instead of pytz.

JGnLAUOAWF
Автор

4:30 pretty sure UTC follows leap seconds, meaning that some days can have more seconds than others.

NateROCKS
Автор

Thanks for this very informative video, I am currently working on a date related project this was a huge life saver.

solidaeon
Автор

Arjan is the big brother/ Mentor that we all needed not sure if we deserved tho.

shashishekhar----
Автор

Really one of the best contents on YouTube, in general. Your videos help me to become a better developer!

janHodle
Автор

There is also the freezgun package to help with datetime sensitive tests

Tweakimp
Автор

Thanks for this Videos! I was facing the timezone conversion problems earlier. This should have come bit earlier😂😂 which would have saved me a lot of time in past. Anyways its never too late. Please keep uploading more videos like this

priyabratapanda
Автор

I thought: "what could I possibly learn about datetime in Python, but I'll watch the video anyway".... and I'm glad I did :) pendulum looks really nice and I only used it to generate timezones

thomasjohanns
Автор

Awesome content, to the point with no fluff 👍🏽

chris
Автор

I recommend dateutil package to everyone who is working with dates. Makes life easy!

xDEAD_Inside
Автор

Yeah. I learned Zulu time in the military. I learned to use it for all coding to avoid all of the silly date/time issues you run into.

Now, if we can just have a standard neutral data type for all types of data....

digiryde
Автор

At first sight, I'm assuming pendulum's 'en' locale is short for 'English/England', based on the use of abbreviations of 'it' & 'nl' in your examples, but in fact the locale is 'American (English)', since we (English/British) also write the day before the month, and generally will use the 24hr clock. I hope they sort this out in later versions.

cybetica