Menu

gitpiper

is_weekday python Code Snippet in 2024

datebeginner

Last Updated: 17 December 2024

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

python snippet similar to is_weekday For You in December 2024

Subscribe to our Newsletter

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

© 2024 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! ✌️