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
SQL Interview Questions Are you preparing for a SQL interview? SQL is a standard database language used for accessing and manipulating data in databases. It stands for Structured Query Language and was developed by IBM in the 1970's, SQL allows us to create, read, update, and delete data with simple yet effective commands.
15+ min read
SQL Tutorial Structured Query Language (SQL) is the standard language used to interact with relational databases. Whether you want to create, delete, update or read data, SQL provides the structure and commands to perform these operations. SQL is widely supported across various database systems like MySQL, Oracl
8 min read
SQL Commands | DDL, DQL, DML, DCL and TCL Commands SQL commands are crucial for managing databases effectively. These commands are divided into categories such as Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), Data Query Language (DQL), and Transaction Control Language (TCL). In this article, we will e
7 min read
SQL Joins (Inner, Left, Right and Full Join) SQL joins are fundamental tools for combining data from multiple tables in relational databases. Joins allow efficient data retrieval, which is essential for generating meaningful observations and solving complex business queries. Understanding SQL join types, such as INNER JOIN, LEFT JOIN, RIGHT JO
5 min read
Normal Forms in DBMS In the world of database management, Normal Forms are important for ensuring that data is structured logically, reducing redundancy, and maintaining data integrity. When working with databases, especially relational databases, it is critical to follow normalization techniques that help to eliminate
7 min read
SQL Query Interview Questions SQL or Structured Query Language, is the standard language for managing and manipulating relational databases such as MySQL, Oracle, and PostgreSQL. It serves as a powerful tool for efficiently handling data whether retrieving specific data points, performing complex analysis, or modifying database
15+ min read
CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi
6 min read
Window Functions in SQL SQL window functions are essential for advanced data analysis and database management. It is a type of function that allows us to perform calculations across a specific set of rows related to the current row. These calculations happen within a defined window of data and they are particularly useful
6 min read
Top 60 DBMS Interview Questions with Answers for 2025 A Database Management System (DBMS) is the backbone of modern data storage and management. Understanding DBMS concepts is critical for anyone looking to work with databases. Whether you're preparing for your first job in database management or advancing in your career, being well-prepared for a DBMS
15+ min read
SQL | WITH Clause SQL queries can sometimes be complex, especially when you need to deal with multiple nested subqueries, aggregations, and joins. This is where the SQL WITH clause also known as Common Table Expressions (CTEs) comes in to make life easier. The WITH Clause is a powerful tool that simplifies complex SQ
6 min read