54Bfx‖

XPh8B‖WeekDay Function

knGHF‖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

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


FVEx2‖Syntax:


  Gq6UR‖WeekDay (SerialDate, [FirstDayOfWeek])

WADQ4‖Parameters:

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

NAuVs‖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.

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

mXgMu‖Value

PGZPg‖VBA Constant

NHbqP‖Description

0

vbUseSystemDayOfWeek

zLssD‖Use system locale settings

1

vbSunday

EWo2z‖Sunday (default)

2

vbMonday

BHVEx‖Monday

3

vbTuesday

TFvid‖Tuesday

4

vbWednesday

fiXHk‖Wednesday

5

vbThursday

A9CRq‖Thursday

6

vbFriday

sBtM4‖Friday

7

vbSaturday

bXcCx‖Saturday


note

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


bBBqF‖Return type:

CPXVo‖Integer

SEjHR‖Error codes:

5 Invalid procedure call

EFSA4‖Example:

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


Sub ExampleWeekDay
    Dim sDay As String
egQ9F‖    ' Return And display the day of the week
    Select Case WeekDay( Now )
nzBDR‖            Case 1: sDay="Sunday"
JAQL6‖            Case 2: sDay="Monday"
N9Bwr‖            Case 3: sDay="Tuesday"
ALFaw‖            Case 4: sDay="Wednesday"
ABVPf‖            Case 5: sDay="Thursday"
6uSxA‖            Case 6: sDay="Friday"
VkJuV‖            Case 7: sDay="Saturday"
    End Select
cmeK7‖    MsgBox "" + sDay,64,"Today Is"
End Sub

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


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