TOP

Function VBA: WeekdayName

Description

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


Syntax WeekdayName

WeekdayName(date)

Or

WeekdayName(date, first_day_of_the_week)

Numbering

By default, the first day of the week is Sunday (1) and the last day is Saturday (7).

To change the numbering so that Monday is the first day of the week (1) and Sunday is the last day of the week (7), add the value 2 as the second argument when using this function:

WeekdayName(date, 2)

Example VBA WeekdayName

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

Sub WeekdayNameExample1()

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

The WeekdayName function can also display a shortened version of the day by passing a value as the second argument:

Sub WeekdayNameExample2()

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

The name of the day according to the date

Using the Weekday and WeekdayName functions, you can get the name of the day of the week from a date:

Sub WeekdayNameExample3()

    MsgBox WeekdayName(Weekday("30/11/2020", 2)) 'Returns: Monday
    
End Sub

Although it is easier to go directly through the formatting function FORMAT:

Sub WeekdayNameExample4()

    MsgBox Format("30/11/2020", "dddd") 'Returns: Monday
    
End Sub
The function that returns the sequence number of the day of the week: WEEKDAY