Created
December 26, 2014 15:34
-
-
Save patrickbeeson/e7e848e3398f287c86ea to your computer and use it in GitHub Desktop.
Python Weekend Checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Function to check if today's date is a weekend day (i.e. Saturday or Sunday) | |
""" | |
import datetime | |
def check_if_weekend(today): | |
try: | |
isinstance(today, datetime.datetime) | |
upper_limit = today + datetime.timedelta(days=(6 - today.weekday())) | |
lower_limit = today + datetime.timedelta(days=(5 - today.weekday())) | |
if today >= lower_limit <= upper_limit: | |
print('It is the weekend!') | |
else: | |
print('It is not the weekend!') | |
except ValueError: | |
print('Your date is not a datetime object.') | |
if __name__ == "__main__": | |
today_date = datetime.datetime.today() | |
check_if_weekend(today_date) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Bro!