The VBA Weekday Function returns an integer (from 1 to 7), representing the day of the week for a supplied date.
The syntax of the function is:
Where the function arguments are:
Date | - | The date that you want to return the weekday of. | ||||||||||||||||||||||||
[FirstDayOfWeek] | - |
An optional FirstDayOfWeek enumeration value, specifying the weekday that should be used as the first day of the week. This can have any of the following values:
If omitted, the [FirstDayOfWeek] argument uses the default value vbSunday. |
The following examples use the VBA Weekday function to return the day of week for the date 12/31/2015 (a Thursday).
' Return the weekday for the date 12/31/2015 (first day of week is Sunday)
Dim wkday As Integer
' The variable wkday now equals 5.
wkday = Weekday( #12/31/2015# ) |
Note that, in the above call to the Weekday function, the [FirstDayOfWeek] argument is omitted and so it uses the default value vbSunday. Therefore, 12/31/2015 (a Thursday) relates to weekday number 5.
' Return the weekday for the date 12/31/2015 (first day of week is Thursday)
Dim wkday As Integer
' The variable wkday now equals 1.
wkday = Weekday( #12/31/2015#, vbThursday ) |
Note that, in the above call to the VBA Weekday function, the [FirstDayOfWeek] argument is set to the value vbThursday. Therefore, 12/31/2015 (a Thursday) relates to weekday number 1.
If the Date argument that is supplied to the Weekday function cannot be interpreted as a valid date, the function returns the error: