Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about how to get the Day of the Week in Python. so without wasting time lets learn about of this.
How to get the Day of the Week in Python
get the Day of the Week in Python
to get the Day of the Week in Python use weekday() By using weekday() we can get the current day in integer. which is count by 0 to 6 where monday is 0 and sunday is 6. you can better understand it by given example.
from datetime import datetime print(datetime.today().weekday())
Output :3
How to get the Day of the Week in Python
to get the Day of the Week in Python just use isoweekday(). By using isoweekday() we can get the current day in integer. which is count by 1 to 7 where monday is 1 and sunday is 7. you can better understand it by given example.
from datetime import datetime print(datetime.today().isoweekday())
Output :4
python day of week
to get the Day of the Week in Python use weekday() By using weekday() we can get the current day in integer. which is count by 0 to 6 where monday is 0 and sunday is 6. you can better understand it by given example.
from datetime import datetime print(datetime.today().weekday())
Output :3
Method 1: Using weekday()
By using weekday() we can get the current day in integer. which is count by 0 to 6 where monday is 0 and sunday is 6. you can better understand it by given example.
from datetime import datetime
print(datetime.today().weekday())
Output :
3
Method 2: Using isowekday()
By using isoweekday() we can get the current day in integer. which is count by 1 to 7 where monday is 1 and sunday is 7. you can better understand it by given example.
from datetime import datetime
print(datetime.today().isoweekday())
Output :
4
Method 3: Using calendar
By using calendar you can find the day. you will understant it by given below example:
from datetime import date
import calendar
var1 = date.today()
print(calendar.day_name[var1.weekday()])
Output :
Thursday
Conclusion
It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?
Also, Read