Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 353
vinay h Avatar asked Apr 01 '15 06:04

vinay h


People also ask

How do you check if a date is weekday 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.

How do I get the current weekday in Python?

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.

How do I check if Python is today is Monday?

today(). isoweekday() == 1 # 1 = Monday, 2 = Tues, etc.


1 Answers

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" 
like image 191
fahad Avatar answered Oct 14 '22 14:10

fahad