Weekday() and WeekdayName() Function in MS Access
Last Updated :
30 Aug, 2024
In Microsoft Access, date-related functions are essential for managing and analyzing time-based data. Among these, Weekday()
and WeekdayName()
functions serve specific purposes for handling days of the week.
In this article, We will learn about the Weekday() and WeekdayName() Functions in MS Access by understanding various examples and so on.
Weekday() Functon
- In MS Access, The weekday() function returns the weekday number for a given date.
- In this function, a date will be passed as a parameter and it returns the weekday of that date.
- By default the 1 is denoted for Sunday and 7 for Saturday. The second parameter will be optional it will be the first day of the week.
Syntax:
Weekday(date, [firstdayofweek])
Parameters for Weekday()
Function
Parameter | Description |
---|
date | Required. A valid date for which the weekday is to be determined. |
firstdayofweek | Optional. Specifies the first day of the week. The values are: 0: For NLS API setting 1: Sunday (default) 2: Monday 3: Tuesday 4: Wednesday 5: Thursday 6: Friday 7: Saturday |
Examples of Weekday() Function
Example 1:
Let's Determine the day of the week for the date June 17, 2020, using the Weekday()
function in MS Access.
SELECT Weekday(#06/17/2020#);
Output:
4
Explanation: The query `SELECT Weekday(#06/17/2020#);` returns the integer value representing the day of the week for June 17, 2020, with 1 for Sunday 2 for Monday and so on.
Example 2:
SELECT Weekday(Date());
Output :
6
Explanation: The query SELECT Weekday(Date())
;
returns the integer value representing the day of the week for the current date. The Date()
function provides the current date, and Weekday()
returns its corresponding day of the week as an integer, where 1 is Sunday, 2 is Monday, and so forth.
WeekdayName() Function
- In MS Access, the WeekdayName() function returns the weekday name.
- In this function, the first function will be the week number and the second parameter will be abbreviate which is optional.
- If we want abbreviation then pass true otherwise pass false and the third parameter will be the first day of the week. It is also optional.
Syntax :
WeekdayName(number, abbreviate, firstdayofweek)
Parameters for WeekdayName()
Functions
Parameter | Description |
---|
number | It Specifies the day of the week. Must be an integer in the range of 1 to 7. |
abbreviate | Optional. If True , returns the abbreviated day name (e.g., "Mon" for Monday). If False or omitted, returns the full day name. |
firstdayofweek | Optional. Specifies the first day of the week. Values are: 0: For NLS API setting 1: Sunday (default) 2: Monday 3: Tuesday 4: Wednesday 5: Thursday 6: Friday 7: Saturday |
Example 1:
Let's Determine the name of the day of the week corresponding to the integer value 1
using the WeekdayName()
function in MS Access.
SELECT WeekdayName(1);
Output :
Sunday
Explanation: The query SELECT WeekdayName(1);
returns the full name of the day of the week for the integer value 1
. In MS Access, 1
represents Sunday when using the default setting where Sunday is considered the first day of the week.
Example 2:
Let's Retrieve the abbreviated name of the day of the week corresponding to the integer value 3
, using Monday
as the first day of the week, with the WeekdayName()
function in MS Access.
SELECT WeekdayName (3, TRUE, 2)
Output:
Wed
Explanation:
The query SELECT WeekdayName(3, TRUE, 2);
returns the abbreviated name of the day of the week for the integer value 3
, where Monday
is set as the first day of the week.
Weekday() vs WeekdayName() Function
Feature | Weekday() Function | WeekdayName() Function |
---|
Purpose | Returns the day of the week as a number (integer). | Returns the name of the day of the week (full name or abbreviated). |
Return Type | Integer (1 to 7) | String (day name in full or abbreviated form) |
Required Parameters | date - A valid date for which the weekday is calculated. | number - An integer between 1 and 7 representing the day of the week. |
Optional Parameters | firstdayofweek - Specifies which day is considered the first day of the week (0-7). | abbreviate - Optional. If True , returns abbreviated day name. If False or omitted, returns full name. firstdayofweek - Optional. Specifies which day is considered the first day of the week (0-7). |
Output Example | Weekday(#2024/09/30#) returns 1 if Sunday is set as the first day of the week. | WeekdayName(1) returns Sunday (default setting with Sunday as the first day of the week). |
Usage Example | SELECT Weekday(#2024/09/30#); - Returns the integer value corresponding to the day of the week for September 30, 2024. | SELECT WeekdayName(1); - Returns the name of the day corresponding to the integer value 1 (Sunday). |
Conclusion
Both Weekday()
and WeekdayName()
functions in MS Access are valuable tools for handling date-related queries. While Weekday()
provides a numeric representation of a date's day, WeekdayName()
offers a more user-friendly day name.
Similar Reads
Second() and Time() Function in MS Access 1. Second() Function : In MS Access, the second() function returns the second part of the datetime. In this function, the datetime will be passed as parameter and it will return the second part of the datetime. The returned integer will be in the range of 0 to 59. Syntax : Second(time) Example-1 : S
1 min read
Year() Function in MS Access Year() : Function in Microsoft Access is used to return the year part of a given date. Syntax : Year (date) Parameter : This method accepts one parameter as mentioned above and described below : date : It is any variant, numeric expression, string expression, or any combination of these that can rep
1 min read
Mid() and Len() Function in MS Access 1. Mid() function : In MS Access the mid() function will extract the string from a given position. In this function 3 parameters will be passed first will be the string and second will be the starting position and last will be the length of the string. Syntax : Mid(string, start, length) Example-1 :
1 min read
WEEKDAY Function and WEEKOFYEAR Function in MariaDB 1. WEEKDAY Function : In MariaDB, The Weekday Function returns the weekday index for a date. In this function, the first parameter will be the Date value. This function returns the weekday index for a date. In WEEKDAY function returns the index value of the weekday given a date value. It works oppos
2 min read
Month() and Minute() Function in MS Access 1. Month() Function : In MS Access, the Month() function returns month part for a given date. In this function, it will take the date as a parameter and it will return the month part. It will the return the integer between 0 to 12. Syntax : Month(date) Example-1 : SELECT Month(#06/11/2020#); Output
1 min read