DAYNAME

DAYNAME is a SQL function that returns the name of the day for a given date. The output is a string representing the day of the week.

DAYNAME(date)

  • date: This parameter refers to the date from which the day of the week is to be extracted. It accepts a value of the DATE, DATETIME, or TIMESTAMP type. DAYNAME(date) returns a string representing the day of the week for the provided date.

Example

SELECT DAYNAME('2023-12-25') AS 'Day';

Output

+-------+
| Day |
+-------+
| Monday|
+-------+

Explanation

The DAYNAME function in SQL returns the day of the week for a specified date. In this example, the function is used to determine the day of the week for December 25, 2023, which returns ‘Monday’.

DAYNAME(date)

  • date: This is the input parameter that specifies the date from which the name of the day will be extracted. It must be a valid expression and in a date data type format.

Example

SELECT DAYNAME('2021-12-22') AS 'Day';

Output

+-------+
| Day |
+-------+
| Wednesday |
+-------+

Explanation

The DAYNAME() function in SQL is used to return the name of the weekday for a specific date. In the given example, it returns ‘Wednesday’ as ‘2021-12-22’ falls on a Wednesday.

DAYNAME(date)

  • date: The parameter represents a valid date expression from which Oracle extracts the day of the week as a string.

Example

SELECT TO_CHAR(date '2022-05-28', 'day') AS day
FROM dual;

Output

SATURDAY

Explanation

The TO_CHAR function in Oracle SQL is used to convert a DATE or TIMESTAMP value to a string. In the above example, the TO_CHAR function has been utilized to retrieve the name of the day from a specific date ‘2022-05-28’. The date is first specified, then the ‘day’ format model is provided as an argument to the TO_CHAR function, which then returns the full name of the day for that specific date. In the case above, the output is ‘SATURDAY’, which is the name of the day for the date ‘2022-05-28’.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.