Thursday, July 2, 2026
HomeLanguagesPython program to print current year, month and day

Python program to print current year, month and day

In this article, the task is to write a Python Program to print the current year, month, and day.

Approach:

  • In Python, in order to print the current date consisting of a year, month, and day, it has a module named datetime. From the DateTime module, import date class
  • Create an object of the date class
  • Call the today( ) function of date class to fetch todays date.
  • By using the object created, we can print the year, month, day(attribute of date class) of today.

Python3




# importing date class from datetime module
from datetime import date
  
# creating the date object of today's date
todays_date = date.today()
  
# printing todays date
print("Current date: ", todays_date)
  
# fetching the current year, month and day of today
print("Current year:", todays_date.year)
print("Current month:", todays_date.month)
print("Current day:", todays_date.day)


Output:

Current date:  2020-12-10
Current year: 2020
Current month: 12
Current day: 10
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6966 POSTS0 COMMENTS