find the current date in python

To find the current date in Python, we have to use the date module from the Python's datetime library.

Here is an example code snippet that shows how to get the current date in Python:

main.py
import datetime

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

print("Today's date is:", current_date)
118 chars
7 lines

The output of this code will be something like:

main.py
Today's date is: 2021-07-16
28 chars
2 lines

In this example, we import the datetime module, which is a standard Python library for working with dates and times.

Then we call the date.today() method to get the current date, and store it in the current_date variable. Finally, we print the current date to the console using the print() function.

gistlibby LogSnag