In this article, we will learn how to find the current day is the weekday or weekends in python. For today's date, we use the datetime.today()
function from datetime
module and weekday()
function to get the week number from the date and check if the week no. is greater than 5 then its a weekend otherwise it is a weekday.
Here is the source code of the program to find the current day is the weekday or weekends in python.
# How to Find the Current Day is Weekday or Weekends in Python
# Import Module
import datetime
# To Get the Week Number
weekNumber = datetime.datetime.today().weekday()
if weekNumber < 5:
print("Today's DateTime is {0} and it's a Weekday".format(datetime.datetime.today()))
else:
print ("Today's DateTime is {0} and it's a Weekend".format(datetime.datetime.today()))
Today's DateTime is 2020-04-29 09:03:24.088097 and it's a Weekday
I hope this article will help you to understand how to find the current day is the weekday or weekends in python.
Share your valuable feedback, please post your comment at the bottom of this article. Thank you!
Comments