Date is weekend

Python, Date · Nov 2, 2020

Checks if the given date is a weekend.

  • Use datetime.datetime.weekday() to get the day of the week as an integer.
  • Check if the day of the week is greater than 4.
  • Omit the second argument, 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

More like this

  • Date is weekday

    Checks if the given date is a weekday.

    Python, Date · Nov 2, 2020

  • Date range

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

    Python, Date · Jan 7, 2021

  • Date from ISO format

    Converts a date from its ISO-8601 representation.

    Python, Date · Jan 7, 2021