Returns an Integer value containing a number representing the day of the week.
Public Function Weekday( _ ByVal DateValue As DateTime, _ Optional ByVal DayOfWeek As FirstDayOfWeek = FirstDayOfWeek.Sunday _ ) As Integer
- Required. Date value for which you want to determine the day of the week.
- Optional. A value chosen from the FirstDayOfWeek enumeration that specifies the first day of the week. If not specified, FirstDayOfWeek.Sunday is used.
The DayOfWeek argument can have one of the following settings.
|FirstDayOfWeek.System||0||First day of week specified in system settings|
|FirstDayOfWeek.Monday||2||Monday (complies with ISO standard 8601, section 3.17)|
The value returned by the Weekday function corresponds to the values of the FirstDayOfWeek enumeration; that is, 1 indicates Sunday and 7 indicates Saturday.
If DayOfWeek is less than 0 or more than 7, an ArgumentException error occurs.
Note Weekday uses the current calendar setting from the CurrentCulture property of the CultureInfo class in the System.Globalization namespace. The default CurrentCulture values are determined by Control Panel settings.
This example uses the Weekday function to obtain the day of the week from a specified date.
Dim MyDate As Date Dim MyWeekDay As Integer MyDate = #2/12/1969# ' Assign a date. MyWeekDay = Weekday(MyDate) ' MyWeekDay contains 4 because ' MyDate represents a Wednesday.
Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)