Using of Datetime Library in python Class 11-12 Notes

As python provides a large set of library, it also contains datetime library. This library displays the date in YYYY-MM-DD format. Python datetime module handles the extraction and formatting of date and time variables. All the attributes can be accessed using dot(.) operator with the date object.


functions in datetime module

Date functions Description
today( ) used to display today’s date
year to display year
month to display month
day to display day
Time functions Description
now() used to display current time
hour to display hour
minute to display minute
second to display second


today() Implementation:


import datetime

#printing today's date
print("Today date is:",date_today)

#printing today's year
print("We are in Year:",date_today.year)

#printing today's month number
print("Today is",date_today.month ,"month of the year")

#printing today's day
print("Today is",,"day of the month")



Today date is: 2022-02-02
We are in Year: 2022
Today is 2 month of the year
Today is 2 day of the month


today module

today module out

now() Implementation:

import datetime

#printing current date and time
print("The current time is:",time_now)

#printing current hour
print("Current hour is",time_now.hour)

#printing current minute
print("Current Minute",time_now.minute)

#printing current seconds
print("Current seconds",time_now.second)



The current time is: 2022-02-02 21:32:32.937900
Current hour is 21
Current Minute 32
Current seconds 32


Check here- digital clock Python Project

By cbsepython

A complete solution for the students of class 9 to 12 having subject Information Technology (402), Computer Science (083). Explore our website for all the useful content as Topic wise notes, Solved QNA, MCQs, Projects and Quiz related to the latest syllabus.

Copywrite © 2020-2024, CBSE Python,
All Rights Reserved