Get the Current Year, month Python

In this article, we are going to learn how we can get the current year, or month or day(date) in Python. We will make use of the datetime module of Python to get the current date and time. Once we have the current year or month or date(day) then we will print it.

Environment & Requirements :
Python interpreter
datetime library

Program to Get the Current year , month, day

from datetime import date
year = date.today().year
month = date.today().month
day = date.today().day
print("The Current Year is =", year)
print("The Current Month is =", month)
print("The Current Day is =", day)

Output –
The Current Year is = 2022
The Current Month is = 12
The Current Day is = 31

Program code explanation:

1. First we need to import the date class from the datetime module
2.Call a today().year on it.
3.The year property returns the current year in four-digit(2022) string format according to the user’s local time.

4. Similarly , call the today.month and today.day properties to get the month and day information.