Files
30-seconds-of-code/snippets/is_weekday.md
Isabelle Viktoria Maciohsek cbc78ee450 Bake dates into snippets
2021-06-13 19:38:10 +03:00

603 B

title, tags, firstSeen, lastUpdated
title tags firstSeen lastUpdated
is_weekday date,beginner 2020-10-28T16:20:18+02:00 2020-11-02T19:28:05+02:00

Checks if the given date is a weekday.

  • Use datetime.datetime.weekday() to get the day of the week as an integer.
  • Check if the day of the week is less than or equal to 4.
  • Omit the second argument, d, to use a default value of datetime.today().
from datetime import datetime

def is_weekday(d = datetime.today()):
  return d.weekday() <= 4 
from datetime import date

is_weekday(date(2020, 10, 25)) # False
is_weekday(date(2020, 10, 28)) # True