Please suggest me on the following. How to find whether a particular day is weekday or weekend in Python?
Check if a date is a weekday or weekend We can use the weekday() method of a datetime. date object to determine if the given date is a weekday or weekend. Note: The weekday() method returns the day of the week as an integer, where Monday is 0 and Sunday is 6. For example, the date(2022, 05, 02) is a Monday.
Use the weekday() Method to Get the Name of the Day in Python. In Python, weekday() can be used to retrieve the day of the week. The datetime. today() method returns the current date, and the weekday() method returns the day of the week as an integer where Monday is indexed as 0 and Sunday is 6.
today(). isoweekday() == 1 # 1 = Monday, 2 = Tues, etc.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With