Skip to content
This repository was archived by the owner on May 7, 2023. It is now read-only.

Files

Latest commit

 

History

History
27 lines (21 loc) · 591 Bytes

is-weekend.md

File metadata and controls

27 lines (21 loc) · 591 Bytes
title type tags cover dateModified
Date is weekend
snippet
date
two-lighthouses
2020-11-02 19:28:05 +0200

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