Let us consider a use case where you want to determine the day of the week of the date selected from a datepicker control or where the date may be input as a text string.
The Weekday() function is used for the purpose. It returns the serial number of the day of the week based on return type which specifies the starting day. 2 is used to specify that Monday would be the first day, 3 specifies that Monday would be 0 through 6 which would be Sunday.
Syntax
WEEKDAY(date, return_type)
Example
datepicker = Apr-29-2019 (Monday)
WEEKDAY(DATESTR( datepicker , “MM/DD/YYYY”))
It Would return 2 as, by default, Sunday is the first day.
In case you specify the return type for the example as follows:
WEEKDAY(DATESTR( datepicker , “MM/DD/YYYY”), 3)
It would return 0 as Monday would be the starting day of the week
Note:
- In this case we are using the DATESTR function to convert the date which is in a Unix format to a readable date format for the weekday function.