Open In App

Weekday() and WeekdayName() Function in MS Access

Last Updated : 30 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

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

ParameterDescription
dateRequired. A valid date for which the weekday is to be determined.
firstdayofweekOptional. 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

ParameterDescription
numberIt 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.
firstdayofweekOptional. 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

FeatureWeekday() FunctionWeekdayName() Function
PurposeReturns the day of the week as a number (integer).Returns the name of the day of the week (full name or abbreviated).
Return TypeInteger (1 to 7)String (day name in full or abbreviated form)
Required Parametersdate - A valid date for which the weekday is calculated.number - An integer between 1 and 7 representing the day of the week.
Optional Parametersfirstdayofweek - 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 ExampleWeekday(#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 ExampleSELECT 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.


Next Article
Article Tags :

Similar Reads