Skip to content

Check if a day is weekday or weekend in Python

To check if a day is weekday or weekend in Python, we basically get the day number using weekday() function and see if it’s > 4 or <4. Easy!


from datetime import datetime
d = datetime(2020, 12, 25);
if d.weekday() > 4:
    print 'Given date is weekend.'
    print 'Given data is weekday.'

See also  How to check if a list is empty in Python?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.