VBA Function: WeekdayName

The VBA WeekdayName function returns the name of the day of the week based on its number.

Usage:

WeekdayName(number)

or

WeekdayName(number, abbreviation, first_day_of_week)


Numbering

By default, the first day of the week is based on your system settings, so you usually don't need to modify it.

If necessary, or to ensure consistent results across different systems, you can set Monday as the first day of the week (1) and Sunday as the last day (7) by adding the value 2 as the third argument when using this function:

WeekdayName(number, abbreviation, 2)

Examples of Usage

Using the WeekdayName function to display the names of the 7 days:

Sub example()

    MsgBox WeekdayName(1) 'Returns: Sunday
    MsgBox WeekdayName(2) 'Returns: Monday
    MsgBox WeekdayName(3) 'Returns: Tuesday
    MsgBox WeekdayName(4) 'Returns: Wednesday
    MsgBox WeekdayName(5) 'Returns: Thursday
    MsgBox WeekdayName(6) 'Returns: Friday
    MsgBox WeekdayName(7) 'Returns: Saturday
    
End Sub

The WeekdayName function can also display the abbreviated version of the day by using the value True as the second argument:

Sub example()

    MsgBox WeekdayName(1, True) 'Returns: Sun
    MsgBox WeekdayName(2, True) 'Returns: Mon
    MsgBox WeekdayName(3, True) 'Returns: Tue
    MsgBox WeekdayName(4, True) 'Returns: Wed
    MsgBox WeekdayName(5, True) 'Returns: Thu
    MsgBox WeekdayName(6, True) 'Returns: Fri
    MsgBox WeekdayName(7, True) 'Returns: Sat
    
End Sub

Day Name Based on a Date

By using the Weekday and WeekdayName functions together, you can obtain the day name based on a date:

Sub example()

    MsgBox WeekdayName(Weekday("11/30/2024")) 'Returns: Saturday
    
End Sub

Although it is simpler to use the Format function directly:

Sub example()

    MsgBox Format("11/30/2024", "dddd") 'Returns: Saturday
    
End Sub