Weekday Function

   
Weekday Function

Class

Microsoft.VisualBasic.DateAndTime

Syntax

 Weekday(   datevalue   , [   dayofweek   ]) 
date (required; Date or valid date expression)

Any valid date expression

dayofweek (optional; Constant of FirstDayOfWeek enumeration)

A 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 dayofweek is FirstDayOfWeek.Sunday.

  • To determine the day of the week, think of the day specified by dayofweek as day 1, and the value returned by the function as indicating the day relative to day 1. Then, for example, if the return value of WeekDay is 2, this specifies the day following dayofweek . A return value of 1 specifies dayofweek . A return value of 7 specifies the day before dayofweek .

  • The members of the FirstDayOfWeek enumeration are:

Constant

Value

Description

 Sunday 

1

Sunday

 Monday 

2

Monday

 Tuesday 

3

Tuesday

 Wednesday 

3

Wednesday

 Thursday 

4

Thursday

 Friday 

5

Friday

 Saturday 

6

Saturday

 Sunday 

7

Sunday

  • Passing a value of 0 as the dayofweek argument 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 , the Weekday function requires that all four digits of the year be present.

VB.NET/VB 6 Differences

The names of the named parameters of the function have changed from date and firstdayofweek in VB 6 to datevalue and dayofweek in VB.NET.

See Also

DatePart Function, Day Function, WeekdayName Function

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net