There are a number of ways we can take to get the current date. We will use the date class of the datetime module to accomplish this task.
Example 1: Python get today's date
Output
Today's date: 2022-12-27
Here, we imported the date class from the datetime module. Then, we used the date.today() method to get the current local date.
Example 2: Current date in different formats
Output
d1 = 27/12/2022 d2 = December 27, 2022 d3 = 12/27/22 d4 = Dec-27-2022
Get the current date and time in Python
If we need to get the current date and time, you can use the datetime class of the datetime module.
Output
now = 2022-12-27 10:09:20.430322 date and time = 27/12/2022 10:09:20
Here, we have used datetime.now() to get the current date and time.
Then, we used strftime() to create a string representing date and time in another format.