Python Check if Date is Weekend or Weekday Example
Today our leading topic is python check if date is weekend or weekday. This post will give you simple example of python check if date is weekend. This tutorial will give you simple example of python check if date is weekday. this example will help you python find if date is weekend. So, let's follow few step to create example of python datetime check if date is weekend.
In this example, we will use datetime library to check date is weekend or weekday. i will give you two simple examples one with current date and another with string date. so let's see both examples:
You can use these examples with python3 (Python 3) version.
Example 1: Python Check Today's Date is Weekend or Weekday
main.py
from datetime import datetime # Get Day Number from weekday weekno = datetime.today().weekday() if weekno < 5: print("Today is a Weekday") else: # 5 Sat, 6 Sun print("Today is a Weekend")
Output:
Today is a Weekday
Example 2: Python Check String Date is Weekend or Weekday
main.py
from datetime import datetime myDateString = "2022-06-04" myDate = datetime.strptime(myDateString, "%Y-%m-%d") # Get Day Number from weekday weekno = myDate.weekday() if weekno < 5: print("Today is a Weekday") else: # 5 Sat, 6 Sun print("Today is a Weekend")
Output:
Today is a Weekend
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Add Seconds to DateTime in Python?
- Python Subtract Minutes from DateTime Example
- Python DELETE Request Example Tutorial
- Python PUT Request with Parameters Example
- Python POST Request with Parameters Example
- Python GET Request with Parameters Example
- Python Subtract Hours from Datetime Example
- How to Get Current Minute in Python?
- How to Get Current Hour in Python?
- How to Get Current Day in Python?