totn Access Functions

MS Access: Weekday Function

This MSAccess tutorial explains how to use the Access Weekday function with syntax and examples.

Description

The Microsoft Access Weekday function returns a number representing the day of the week (a number from 1 to 7) given a date value.

Syntax

The syntax for the Weekday function in MS Access is:

Weekday ( date_value, [firstdayofweek] )

Parameters or Arguments

date_value
A valid date.
firstdayofweek

Optional. It determines what day is to be the first day of the week. If omitted, it assumes that the first day of the week is Sunday. It can be any of the following values:

Constant Value Explanation
vbUseSystem 0 Use the NLS API settings
vbSunday 1 Sunday (default used)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday

Returns

The Weekday function returns a numeric value.

Note

  • If you use the Weekday function in a query, you'll have to use the numeric value (ie: 0 to 7) for the firstdayofweek parameter. You can only use the constant equivalent (ie: vbSunday to vbSaturday) in VBA code.

Applies To

The Weekday function can be used in the following versions of Microsoft Access:

  • Access 2019, Access 2016, Access 2013, Access 2010, Access 2007, Access 2003, Access XP, Access 2000

Example

Let's look at how to use the Weekday function in MS Access:

Weekday (#22/11/2003#)
Result: 7

Weekday (#22/11/2003#, vbThursday)
Result: 3

Weekday (#22/11/2003#, 5)
Result: 3

Weekday (#01/01/1998#)
Result: 5

Example in VBA Code

The Weekday function can be used in VBA code in Microsoft Access.

For example:

Dim LWeekday As Integer

LWeekday = Weekday(#12/03/2001#, vbSunday)

In this example, the variable called LWeekday would now contain the value of 2.

Example in SQL/Queries

You can also use the Weekday function in a query in Microsoft Access.

For example:

Microsoft Access

In this query, we have used the Weekday function as follows:

Expr1: Weekday(#12/03/2001#,1)

and

Expr2: Weekday([CategoryDate],3)

The first Weekday function will extract the weekday value (1 to 7) from the date value 12/03/2001, assuming that Sunday is the first day of the week (1 as the second parameter). The results will be displayed in a column called Expr1. You can replace Expr1 with a column name that is more meaningful.

For example:

WeekdayValue: Weekday(#12/03/2001#,1)

The results would now be displayed in a column called WeekdayValue.

The second Weekday function will extract the weekday value from the CategoryDate field, assuming that the first day of the week is Tuesday (3 as the second parameter). The results will be returned in a column called Expr2.