Please suggest me on the following. How to find whether a particular day is weekday or weekend in Python?
Asked
Active
Viewed 9.2k times
2 Answers
153
You can use the .weekday() method of a datetime.date object
import datetime
weekno = datetime.datetime.today().weekday()
if weekno < 5:
print "Weekday"
else: # 5 Sat, 6 Sun
print "Weekend"
26
Use the date.weekday() method. Digits 0-6 represent the consecutive days of the week, starting from Monday.
Jacob Jones
- 123
- 8
Michał Szydłowski
- 3,104
- 3
- 32
- 51