You can use the weekday()
method from the datetime
module in Python to check if a given date is a Saturday or Sunday. The weekday()
method returns an integer where Monday is 0 and Sunday is 6.
Here is an example of how to check if a given date is a Saturday or Sunday:
main.py568 chars22 lines
This will output:
main.py25 chars2 lines
Alternatively, you can also use the strftime
method to directly format the date object and check if it matches "Saturday" or "Sunday" strings:
main.py581 chars22 lines
This will output the same result as before:
main.py25 chars2 lines
Remember to replace the date_string
variable with the date you want to check in the format "YYYY-MM-DD".
gistlibby LogSnag