WeekDay Function

This function returns the number corresponding to the weekday represented by a serial date number that is generated by the DateSerial or the DateValue functions.

note

This help page describes the WeekDay function used in Basic scripts. If you are interested in the WeekDay function used in LibreOffice Calc, refer to this help page.


Syntax:


  WeekDay (SerialDate, [FirstDayOfWeek])

Parameters:

SerialDate: Integer expression that contains the serial date number that is used to calculate the day of the week.

FirstDayOfWeek: Integer value indicating which weekday should be considered as the first day of the week. The default value is 0, meaning that the system locale settings are used to determine the first day of the week.

The parameter FirstDayOfWeek accepts values ranging from 0 to 7. The table below describes the meaning of each possible value:

āĻŽāĻžāύ

VBA Constant

āĻŦāĻŋāĻŦāϰāĻŖ

0

vbUseSystemDayOfWeek

Use system locale settings

1

vbSunday

āϰāĻŦāĻŋāĻŦāĻžāϰ (āĻĄāĻŋāĻĢāĻ˛ā§āϟ)

2

vbMonday

āϏ⧋āĻŽāĻŦāĻžāϰ

3

vbTuesday

āĻŽāĻ™ā§āĻ—āϞāĻŦāĻžāϰ

4

vbWednesday

āĻŦ⧁āϧāĻŦāĻžāϰ

5

vbThursday

āĻŦ⧃āĻšāĻ¸ā§āĻĒāϤāĻŋāĻŦāĻžāϰ

6

vbFriday

āĻļ⧁āĻ•ā§āϰāĻŦāĻžāϰ

7

vbSaturday

āĻļāύāĻŋāĻŦāĻžāϰ


note

The VBA constants listed above are only available if VBA support has been enabled. For more information, read the VBASupport Statement help page.


Return value:

Integer

Error codes:

5 Invalid procedure call

Example:

The following example uses the function Now() to determine the current weekday.


Sub ExampleWeekDay
    Dim sDay As String
    REM āĻĒā§āϰāĻĻāĻžāύ āĻ•āϰ⧇ āĻāĻŦāĻ‚ āϏāĻĒā§āϤāĻžāĻšā§‡āϰ āĻĻāĻŋāύ āĻĒā§āϰāĻĻāĻ°ā§āĻļāύ āĻ•āϰ⧇
    Select Case WeekDay( Now )
            Case 1: sDay="Sunday"
            Case 2: sDay="Monday"
            Case 3: sDay="Tuesday"
            Case 4: sDay="Wednesday"
            Case 5: sDay="Thursday"
            Case 6: sDay="Friday"
            Case 7: sDay="Saturday"
    End Select
    msgbox "" + sDay,64,"Today is"
End Sub

The following example illustrates the use FirstDayOfWeek parameter, assuming that Tuesday is the first day of the week.


  Dim someDay As Long
  ' The date January 1st 2021 was a Friday
  someDay = DateSerial(2021, 01, 01)
  ' Prints "6" assuming Sunday is the first day of the week
  MsgBox WeekDay(someDay)
  ' Prints "4" assuming Tuesday is the first day of the week
  MsgBox WeekDay(someDay, 3)

Please support us!