Saturday Week Day

  • The following is some code that takes a certain date and populates the week field with the next Saturday date from that date field:

    eg.

    Date Week

    8/11/2003 8/16/2003

    8/4/2003 8/9/2003

    The problem I'm getting is when the date is actually Saturday, it is populating with the next week

    eg

    8/9/2003 8/16/20003 and it should be 8/9/2003.

    Set datefirst 7

    update timesheet_daily

    set week=DATEADD(DAY,CASE WHEN (7-DATEPART(Weekday,[DATE])) = 0

    THEN 7

    ELSE (7-DATEPART(WEEKDAY,[DATE]))

    end,[date])

    where date <=(select Earn_Period_End

    from timesheet_pay_period where getdate() between

    Earn_Period_Start and Earn_Period_End)

    Any help would be appreciated!

    Thanks!!

  • Actually, I changed it so instead of adding 7, I add 0. I was thinking that Saturday was still weekday 6, not 7.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply