Home »
Python »
Python programs
Python program to print today's year, month and day
Here, we are going to learn how to print today's year, month and day in Python programming language? This is an example of datetime module in Python.
Submitted by IncludeHelp, on March 09, 2020
In the below example – we are implementing a python program to print the current/ today's year, month and year.
Steps:
- Import the date class from datetime module
- Create a date object of today's date – call the today() function of date class to get the current date.
- By using the date object – we can extract and print today's year, month and day.
# Python program to
# print today's year, month and day
# importing the date class datetime module
from datetime import date
# creating the date object of today's date
current_date = date.today()
# printing the current date
print("Current date: ", current_date)
# extracting the current year, month and day
print("Current year:", current_date.year)
print("Current month:", current_date.month)
print("Current day:", current_date.day)
Output
Current date: 2020-03-09
Current year: 2020
Current month: 3
Current day: 9
ADVERTISEMENT
ADVERTISEMENT