Python Date & Time

In this Python tutorial, let us discuss the python date and time with suitable examples.

Introduction of Python Date & Time

A date in Python is not a data type of its own, but we can import a module named datetime to work with dates as date objects.

Importing date and time

import datetime
x =

The above code will display the current date and time of the system.

Creating Date Objects

To create a date, we can use the datetime() class (constructor) of the datetime module.

The datetime() class requires three parameters to create a date: year, month, day.

Example code to create a date objects

import datetime
x = datetime.datetime(2020, 5, 17)


2020-05-17 00:00:00

Leave a Comment

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