7554425D-0054-440D-B95E-D2ABC13D62CD Created with sketchtool.
{body}
Your Saved Info Packages

View your saved Course or Program Packages containing pricing and detailed curriculum.

Speak with a Learning Advisor.

Have any questions? We'll call you.

Fill out the form below and a Learning Advisor will reach out at a time convenient for you.

Please pick a valid date and time between 9 AM and 8 PM eastern (Monday to Friday)

By clicking "Book a call," you accept our Terms and will also receive exclusive offers and updates about new courses, workshops and events.

Python Tutorial

Python Datetime Module

Ready to start your career in Data? Find out more about BrainStation's Python Course

Python provides a huge collection of built-in modules that can be readily used while writing code in Python. A module is basically a collection of useful classes and each class has attributes and methods available for use. This helps developers to not reinvent the wheel for common tasks and focus on the big picture implementation. One such module that is quite useful is Datetime.

The Datetime module provides a collection of useful methods for working with date and time in Python. Let’s dive into this module and all the features it provides.

Some of the most common tasks you can do with datetime module are:

  • Get current date and time
  • Create new date if year, month and day are known
  • Create time object if hour, minute, second is known
  • Get date and time if Unix timestamp is known

We have barely touched the surface with these common tasks. Datetime is a great module with many other amazing features that comes handy for various tasks around date and time in Python.

Any built-in Python module can be used by first importing it at the top of the file using import keyword.

Let’s see how to use the datetime module and it’s built-in features in Python.

A datetime object can also be created manually by specifying year, month, day, hour, minute, seconds and timestamp or a combination of these values. You can also find the difference between two time objects using timedelta.

Set Password

You already have an account with BrainStation, but you still need to set up a password.