Name
Weekday Function
Class
Microsoft.VisualBasic.DateAndTime
Syntax
Weekday(datevalue, [dayofweek])-
date Use: Required
Data Type: Date or valid date expression
Any valid date expression
-
dayofweek Use: Optional
Data Type: Constant of
FirstDayOfWeekenumerationA constant indicating the first day of the week
Return Value
Integer
Description
Determines the day of the week of a given date
Rules at a Glance
The default for
dayofweekisFirstDayOfWeek.Sunday.To determine the day of the week, think of the day specified by
dayofweekas day 1, and the value returned by the function as indicating the day relative to day 1. Then, for example, if the return value ofWeekDayis 2, this specifies the day followingdayofweek. A return value of 1 specifiesdayofweek. A return value of 7 specifies the day beforedayofweek.The members of the
FirstDayOfWeekenumeration are:Constant
Value
Description
Sunday1
Sunday
Monday2
Monday
Tuesday3
Tuesday
Wednesday3
Wednesday
Thursday4
Thursday
Friday5
Friday
Saturday6
Saturday
Sunday7
Sunday
Passing a value of 0 as the
dayofweekargument uses the system’s locale settings to determine the first day of the week.
Example
Since the code:
Weekday(#3/26/2001#, FirstDayOfWeek.Sunday)
returns 2, the date 3/26/2001 is a Monday.
Programming Tips and Gotchas
If passing a date literal as
datevalue, theWeekdayfunction requires that all four digits of the year be present.That the function’s return value is relative to
dayofweek ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access