Python Date Time Calendar – Python Programming

Learn Python Programming from Basic to Advanced Concept with Examples. Learn Python DateTime, Time, Date, Calendar and Timezone.
Image by Michal Jarmoluk from Pixabay

Python Date Time can be used in Python by importing DateTime Modules. We can also work with Calendar using the Calendar Module.

Importing Date Time and Calendar Modules

import datetime
import calendar
Python Date Time Calendar Video Tutorial

Python DateTime

Once we have imported modules then we can work on a date, time and calendar in Python

import datetime
x = datetime.datetime.now()
print(x)

If you want specific Year, Month, Day then

x = datetime.datetime.now()

print(x)
print(x.year)
print(x.strftime("%B"))
print(x.strftime("%A"))

Create DateTime Object or Variable

For creating user-defined DateTime object use DateTime module name. For Example – 

y = datetime.datetime(2020,8,19)
print(y)

Python Calendar

We can work with the calendar using the calendar module. For printing a specific month of the year. For Example:

cal = calendar.month(2017,2)
print(cal)

Whats Next – Python Function

Share