How to get current date in Python?

Python | Get current date: In this tutorial, we will learn how to get the current date using Python program? By IncludeHelp Last updated : December 28, 2023

In the below example – we are implementing a python program to get the current date.

Getting current date in Python

To get the current date, you can use the today() method of datetime module, this module provides classes for getting, creating, and manipulating dates and times.

Steps to get current date

  • Import the date class from datetime module.
    from datetime import date
  • Call today() function which is a library function of date class.
    current_date = date.today()
  • Finally, print the date.
    print("Current date is: ", current_date)
    

Python program to get current date

# How to get current date in Python? 

# importing the date class 
# from datetime module
from datetime import date

# getting the current date
current_date = date.today()

# printing the date
print("Current date is: ", current_date)

Output

Current date is:  2020-03-09

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.