|
MS Access dates & queries
|
Revised: 3/16/2013
Owner: Administrator |
MS Access: Weekday Function
In Microsoft Access, the 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 is:
Weekday ( date_value, [firstdayofweek] )
date_value is a valid date.
firstdayofweek is optional. It determines what day is to be the first day of the week. 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
|
If this parameter is omitted, the Weekday function assumes that the first day of the week is Sunday.
Please note that 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
· Access 2010, Access 2007, Access 2003, Access XP, Access 2000
For Example
Weekday (#22/11/2003#)
|
would return 7
|
Weekday (#22/11/2003#, vbThursday)
|
would return 3
|
Weekday (#22/11/2003#, 5)
|
would return 3
|
Weekday (#01/01/1998#)
|
would return 5
|
VBA Code
The Weekday function can be used in VBA code. 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.
SQL/Queries
You can also use the Weekday function in a query.
888888********************************************************************************************************************************************
Query the Day from a Date field in Microsoft Access
Using an expression in a Microsoft Access query design will enable you to find the day from a date field stored in the database table. This may be helpfull if you wish to monitor sales by a particular day of the week.
You can simply use the following Microsoft Access Format function to display the day:
Format([YourDateField],"dddd")
The example below shows this to display what day a person was born on, by using the format function against the date of birth field:
Query design showing the Format function
Using this will now display the results, showing the day derived from the DateOfBirth field:
in a date field, you can just change the display format to show the date any way you want
any combination of these, plus am pm, and stuff like that
"dddd dd/mmm/yy hh:mm:ss" or
"dddd dd/mm/yy hh:mm:ss"
dddd - shows day in full
ddd - abbreviated day (3 chars)
dd - date as 2 digit number
mmmm - month in full
mmm - abbreviated month (3 chars)
mm - month as 2 digits
*************************************************************************
Skip to main content
|
|
MS Access dates & queries
|
MS Access: Weekday Function
In Microsoft Access, the 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 is:
Weekday ( date_value, [firstdayofweek] )
date_value is a valid date.
firstdayofweek is optional. It determines what day is to be the first day of the week. 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
|
If this parameter is omitted, the Weekday function assumes that the first day of the week is Sunday.
Please note that 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
· Access 2010, Access 2007, Access 2003, Access XP, Access 2000
For Example
Weekday (#22/11/2003#)
|
would return 7
|
Weekday (#22/11/2003#, vbThursday)
|
would return 3
|
Weekday (#22/11/2003#, 5)
|
would return 3
|
Weekday (#01/01/1998#)
|
would return 5
|
VBA Code
The Weekday function can be used in VBA code. 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.
SQL/Queries
You can also use the Weekday function in a query.
888888********************************************************************************************************************************************
Query the Day from a Date field in Microsoft Access
Using an expression in a Microsoft Access query design will enable you to find the day from a date field stored in the database table. This may be helpfull if you wish to monitor sales by a particular day of the week.
You can simply use the following Microsoft Access Format function to display the day:
Format([YourDateField],"dddd")
The example below shows this to display what day a person was born on, by using the format function against the date of birth field:
Query design showing the Format function
Using this will now display the results, showing the day derived from the DateOfBirth field:
in a date field, you can just change the display format to show the date any way you want
any combination of these, plus am pm, and stuff like that
"dddd dd/mmm/yy hh:mm:ss" or
"dddd dd/mm/yy hh:mm:ss"
dddd - shows day in full
ddd - abbreviated day (3 chars)
dd - date as 2 digit number
mmmm - month in full
mmm - abbreviated month (3 chars)
mm - month as 2 digits
*************************************************************************
Skip to main content
|
3/16/2013
|
info, web
|
Administrator
|
|
|
|
|