isoweekday()

isoweekday() : day of the week as integer, Sunday =0 , Monday =1 ....

Today's isoweekday()
from datetime import date
dt=date.today()
print(dt.isoweekday())
Output
2
Using date and time object
from datetime import datetime
dt=datetime(2019,12,31)
print(dt.isoweekday())
Output
2
Example with weekday()
from datetime import date
dt = date.today()
print(dt.weekday())      # Monday = 0
print(dt.isoweekday())   # Monday = 1

Example 1: Determine if a Date Falls on a Weekend

from datetime import date
dt = date(2024, 9, 14)
if dt.isoweekday() in [6, 7]:
    print(f"{dt} is a weekend.")
else:
    print(f"{dt} is a weekday.")
Output
2024-09-14 is a weekend.

Example 2: Check Day for Next 7 Days

from datetime import date, timedelta
today = date.today()
for i in range(7):
    future_date = today + timedelta(days=i)
    print(future_date, future_date.isoweekday())
Output
2024-09-14 6
2024-09-15 7
2024-09-16 1                                        
2024-09-17 2                                        
2024-09-18 3
2024-09-19 4
2024-09-20 5
2nd Saturday Display 2nd and 4th Saturday of the month
calendarCalendar module to Create yearly or monthly Calendars
All Date Objects
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer