Weekday

Returns a number representing the day of the week (a number from 1 to 7) for a given date value.

Syntax
      Weekday ( date, [firstdayofweek] )

Key
   date            Any valid date expression.
firstdayofweek A constant that specifies the first day of the week default = 1 or vbSunday. if set to 0 or vbUseSystem it will use the NLS API setting - see List of Locales

The weekday() function can be used in VBA or in an SQL query. The vb constants can only be used in VBA.

To create day numbers compatible with ISO 8601 standard dates, set thefirstdayofweek to Monday(2 or vbMonday)

Examples

Dim intDay as Integer
intday = weekday("30/04/2012",2)
Wscript.Echo intDay
'
will return 1 (Monday)

A function to determine if it is the weekend:

Function IsWeekend(dtm as Date)
'Returns True if dtm is a Saturday or Sunday
If Weekday (dtm,vbMonday) = 6 or Weekday (dtm,vbMonday) = 7 Then
   IsWeekend = True
Else
   IsWeekend = False
End If
End Function

“A committee is a thing which takes a week to do what one good man can do in an hour” ~ Elbert Hubbard

Related

Date - Return the current date.
DatePart - Return part of a given date.
MonthName - Return a string representing the month.
Format - Format a Number/Date/Time.
WeekdayName - Return the day of the week.
Standard date and time notation - YYYY-MM-DD


 
Copyright © 1999-2024 SS64.com
Some rights reserved