Skip to content

Day of the week #130694

@JLamb0429

Description

@JLamb0429

Bug report

Bug description:

Hello I was writing out a date time program, I wanted to test if today was a week day. 0:Sunday 6:Saturday. For what ever reason it is reporting the today.weekday() as being 1 day behind. Today is Friday February 28th yet the results keep returning as

2025-02-28 09:59:50.472268
4
Thursday
Yes today is a weekday

Here is my code:

import datetime
import datetime as dt

dayDic = {0:"Sunday", 1:"Monday", 2:"Tuesday", 3:"Wednesday", 4:"Thursday", 5:"Friday", 6:"Saturday" }

def CheckifWeekDay():
    global dayDic
    # Check to see if today is one of the business days of the week Monday tru Friday

    # Variables
    today = dt.datetime.today() # get the numerical value of the day of the week 0 = Sunday 6 = Saturday
    Days_MF = [1,2,3,4,5] # List of days of the week 1=Monday 5=Friday
    isMyDay = False # Use this to return values as true of False (default False) it is not a weekday

    # Run through the length of the list days of the weeks and compares it to the current day.
    for i in range(len(Days_MF)):
        if today.weekday() == Days_MF[i]:
            print(today)
            print(today.weekday())
            print(dayDic[today.weekday()])
            print("Yes today is a weekday")
            isMyDay = True # changes isMyDay to True
        else:
            pass
    return isMyDay # returns isMyDay

My IDE is PyCharm, my OS is windows 11. Thank you.

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions