Python Tutorial: Datetime Module – How to work with Dates, Times, Timedeltas, and Timezones



In this Python Tutorial, we will be learning how to use the datetime module. The datetime module is important to understand, because you will be working with dates and times in just about every application you write. We will look at how to work with dates, times, datetimes, timedeltas, and timezones. Let’s get started.

The code from this video can be found at:

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey’s Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:
My Website –
My Second Channel –
Facebook –
Twitter –
Instagram –

#Python

Nguồn: https://benjaminjcohen.com/

Xem thêm bài viết khác: https://benjaminjcohen.com/cong-nghe/

32 Comments

  1. Is necessary to learn about this module datetime ? bcz is so hard to memorize that ..Any Help Please

  2. Omg this guys bday is the same day as my bday

  3. This is great. The datetime module is surprisingly confusing.

  4. Is it necessary to use aware objects if the system you are running this on is on UTC? Or should I always use aware objects? I’m running most of my code on a Raspberry Pi 4B 4 Gibibyte model with the system time set to be UTC.

  5. I wonder why someone would have disliked this video 😳
    Anyways, love your amazing tutorials, pls keep it up 🤗👍

  6. Whats the differnece between these two? They output the same thing?Is the 2nd more efficient or something?
    dt_UTC = datetime.datetime.now(tz=pytz.UTC)

    dt_Wherever = dt_UTC.astimezone(pytz.timezone('Asia/Manila'))

    print(dt_Wherever)

    DT_Wherever = datetime.datetime.now(tz=pytz.timezone('Asia/Manila'))

    print(DT_Wherever)

  7. Hi all. Datetime can be a real pain! I wrote up some complimentary documentation for managing Date, Datetime, and Timestamp in Python/Pandas. You might find it useful. Check it out: https://medium.com/@deallen7/managing-date-datetime-and-timestamp-in-python-pandas-cc9d285302ab

  8. how can we convert given GMT time (2020-05-28 15:34:10) to IST

  9. How to convert current date time in to yyyy-mm-ddThh:mm:ss.000Z format ???? Please someone help me.

  10. I wanted to confirm if pytz is available free in library or it is a third party tool

  11. Fantastic reference! Thank you!

  12. Great video!
    Question: Does pandas.DataFrame.tz_localize work the same or as well as pytz's functions? At first it seemed more basic than pytz, but I see examples on stackoverflow where they use this function and 'US/Eastern' in order to localize a timestamp index in a dataframe (which is what I'm trying to do!). It seems it would be a little easier to use pandas functionality without importing pytz, but wanted to get some pros/cons from anybody here. Thanks!

  13. Thank you Corey!

  14. Error -ModuleNotFound:No module named pytz
    I ran through many links on google but this error is still seen and I am not able to proceed..
    Any solutions ??

  15. Excellent videos. I am new to python. Used to do engineering/ scientific programming many many (*n! ) years ago. Used Fortran at that time.
    I am really enjoying learning Python with such clear videos and a user friendly language. May you "Live long and prosper " !!!!!

  16. I want to make a stopwatch. Let's say that i have 5 runners and only one track. They start running with 10 seconds from each other, because i only have one track. How do i know the lap time of the third athlete? They ran 8 laps of 400 meters. How do i know each lap time of each one? I hope you could help!

  17. Hey Corey! Could you please make a video on the Arrow module as you've mentioned in this video. Looking forward to it. Thanks

  18. great video, this helped me a lot, thanks, keep doing a videos like this, you are best )

  19. Hey man i need ur help please male me.. @ mikebong56@gmail.com plz plz mail me i really need ur help I'm stuck with date from last one month.. Plz

  20. Hi Corey, Even 3.5 years later. I found this to be the best explanation after searching around for 2 hrs…. Thank You 🙂
    Can you please make the video on Arrow though 🙂

  21. Such great videos made. I hope you are making a lot of money from them.

  22. never commented on any video but trust me you are best at what you are doing. Great work. you make the topics crystal clear.

  23. what text editor are you using

  24. this is a good 27 mins of my learning thank you sir

Leave a Reply

Your email address will not be published. Required fields are marked *