datetime.datetime.weekday()
to get the day of the week as an integer.4
.d
, to use a default value of datetime.today()
.from datetime import datetime
def is_weekend(d = datetime.today()):
return d.weekday() > 4
from datetime import date is_weekend(date(2020, 10, 25)) # True is_weekend(date(2020, 10, 28)) # False
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️