Date is weekday

Isabelle Viktoria Maciohsek · Python, Date · Nov 2, 2020

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
from datetime import datetime

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

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

Recommended snippets

  • Date is weekend

    Python, Date

    Checks if the given date is a weekend.

  • Add days to date

    Python, Date

    Calculates the date of n days from the given date.

  • Date range

    Python, Date

    Creates a list of dates between start (inclusive) and end (not inclusive).