This tutorial shows how you can get the current weekday in Python with 2 examples.
Method 1: use weekday()
Method 2: use isoweekday()
Examples of getting current weekday in Python
Example 1 for method 1
We can also check which weekday it is using weekday()
. It returns the day of the week as an integer, where Monday is 0 and Sunday is 6.
Week day | weekday() |
---|---|
Monday | 0 |
Tuesday | 1 |
Wednesday | 2 |
Thursday | 3 |
Friday | 4 |
Saturday | 5 |
Sunday | 6 |
import datetime weekday_date = datetime.date.today().weekday() print("weekday:", weekday_date)
Output:
weekday: 5
Example 2 for method 2
The function isoweekday()
returns an integer to represent the day of the week. Different from weekday()
in Example 1, isoweekday()
returns 1 for Monday and 7 for Sunday.
Week day | isoweekday() |
---|---|
Monday | 1 |
Tuesday | 2 |
Wednesday | 3 |
Thursday | 4 |
Friday | 5 |
Saturday | 6 |
Sunday | 7 |
import datetime weekday_date = datetime.date.today().isoweekday() print(weekday_date)
Output:
4