Google News
logo
Python Program to Import the datetime module and display the current date
In the following example of Python program that imports the `datetime` module and displays the current date :
Program :
import datetime

# get the current date
current_date = datetime.datetime.now().date()

# print the current date
print("Current date:", current_date)
Output :
Current date: 2023-04-27
This program first imports the `datetime` module, which provides classes for working with dates and times. It then uses the `datetime.now()` method to get the current date and time as a `datetime` object, and the `date()` method to extract just the date part of the object.

Finally, it prints the current date using the `print()` function.