September 24, 2021

7 thoughts on “Excel Weekday Function

  1. I have created this function to get first date of week as Thursday in ms access form and reports, but this function return first day of week in las month, but I need it will return only current month dates, if current week first day is in last month then retrun first day of week as 1st date of week in current month.

    ‘current output

    ‘when 1-10-2018 is selected from date picker it returns 27-09-2018, which is first date of week in last month but I need it will return 1st of month which is selected in textbox.

    Function GetFirstofWeek(dtDate As Date)

    'GetFirstofWeek = DateAdd("d", dtDate, -(Weekday(dtDate)) + 1)

    ' Excel formula for this function which is perfect and may be converted to function as required ‘=MAX(B2-WEEKDAY(B2,14)+1, EOMONTH(B2, -1)+1)

    GetFirstofWeek = DateAdd("d", dtDate, -(Weekday(dtDate, vbThursday) – 1))

    End Function

    'For last day of week

    Function GetLastofWeek(dtDate) as date

    '=MIN(B2+(7-WEEKDAY(B2,14)), EOMONTH(B2, 0))

    GetLastofWeek = DateAdd("d", dtDate, (7 – (Weekday(dtDate, vbWednesday)) + 1))

    End Function

    In this function last date of week must be in current month, if month end on first date of then week will be closed and last date of week will be 1st date of week or days remaining in current week.

  2. I have question to ask,

    I want to display first and day of week, week starts from Thursday to Wednesday, if the start date of month is on tuesday then first date of week will be tuesday of the current month, same case on last date of week, if week ends on monday then last date of week will be monday of only in current month, without going to next month last week day.

    Out expected
    For last month
    1-09-2018 to 05-09-2018
    27-09-2018 to 30-09-2018

    For current month
    1-10-2018 to 3-10-2018
    4-10-2018 to 10-10-2018
    11-10-2018 to 17-10-2018
    18-10-2018 to 24-10-2018
    25-10-2018 to 31-10-2018

Leave a Reply

Your email address will not be published. Required fields are marked *