Menu

gitpiper

is_weekend python Code Snippet in 2022

datebeginner

Last Updated: 26 November 2022

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

python snippet similar to is_weekend For You in November 2022

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2022 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️