How to Get the Current Date in Python

This tutorial will show you how to get the current date in Python. It will also show you how to print the weekday in English like Monday, Tuesdady, Wednesday, etc.

Use today() to get the date in number format in Python

We can ask Python to return the current date by using the date.today() in the module of datetime. In particular, date.today() creates a datetime.date instance with the current local date.

import datetime
Current_date = datetime.date.today()
print(Current_date)

The following shows the print out of the current date.

2022-04-18

Use date_name to get English name of weekday in Python

The following code shows you how to get the weekday name in English like Monday, Tuesday format. The weekday() method in datetime.date will return numbers, such that Monday is 0 and Sunday is 6.

Thus, we need to use the Calendar module to change it into English. In particular, it uses the date_name[] to change a number into the weekday in English.

import datetime
import calendar
Current_date = datetime.date.today()
print(Current_date)
print(Current_date.weekday())
print(calendar.day_name[Current_date.weekday()])

After running the code above, the following is the output.

2022-04-18
0
Monday

For a more comprehensive tutorial about date and time in Python, please reivew my other tutorial.