How to Check if Today is Tuesday or not in Python?

By Hardik Savani June 24, 2022 Category : Python

Hi,

In this example, you will learn python check date is tuesday. I would like to show you how to check if today is tuesday in python. you will learn how to check if today is tuesday in python. This tutorial will give you simple example of python today is tuesday.

In this example, we will use DateTime library to check whether today is Tuesday or not. I will give you two simple examples one using weekday() and another using isoweekday(). so let's see both examples:

You can use these examples with python3 (Python 3) version.

Example 1:

main.py

from datetime import datetime
  
# If today is Tuesday (0 = Mon, 1 = Tue, 2 = Wen ...)
if datetime.today().weekday() == 1:
    print("Yes, Today is Tuesday")
else:
    print("Nope...")

Output:

Yes, Today is Tuesday

Example 2:

main.py

from datetime import datetime
  
# If today is Tuesday (1 = Mon, 2 = Tue, 3 = Wen ...)
if datetime.today().isoweekday() == 2:
    print("Yes, Today is Tuesday")
else:
    print("Nope...")

Output:

 
Yes, Today is Tuesday

I hope it can help you...

Tags :