how to find current day is weekday or weekends in Python?

PythonPython 2.7Python 3.x

Python Problem Overview


Please suggest me on the following. How to find whether a particular day is weekday or weekend in Python?

Python Solutions


Solution 1 - Python

You can use the .weekday() method of a datetime.date object

import datetime

weekno = datetime.datetime.today().weekday()

if weekno < 5:
    print "Weekday"
else:  # 5 Sat, 6 Sun
    print "Weekend"

Solution 2 - Python

Use the date.weekday() method. Digits 0-6 represent the consecutive days of the week, starting from Monday.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionvinay hView Question on Stackoverflow
Solution 1 - PythonfahadView Answer on Stackoverflow
Solution 2 - PythonMichał SzydłowskiView Answer on Stackoverflow