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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.