Categories:

Date & time functions

DAYNAME

Extracts the three-letter day-of-week name from the specified date or timestamp.

Note

To return the full name for the day of the week instead of the three-letter day-of-week name, you can use the EXTRACT function, the DECODE function, and the dayofweek part. See EXTRACT for an example.

Syntax

DAYNAME( <date_or_timestamp_expr> )
Copy

Arguments

date_or_timestamp_expr

A date, a time, a timestamp, or an expression that can be evaluated to a date, a time, or a timestamp.

Returns

Returns a value of VARCHAR data type.

Examples

Use the TO_DATE function to get the abbreviation for the day of the week of April 1, 2024:

SELECT DAYNAME(TO_DATE('2024-04-01')) AS DAY;
Copy
+-----+
| DAY |
|-----|
| Mon |
+-----+

Use the TO_TIMESTAMP_NTZ function to get the abbreviation for the day of the week of April 2, 2024:

SELECT DAYNAME(TO_TIMESTAMP_NTZ('2024-04-02 10:00')) AS DAY;
Copy
+-----+
| DAY |
|-----|
| Tue |
+-----+

Get the abbreviation for the day of the week for each day from January 1, 2024, to January 8, 2024:

CREATE OR REPLACE TABLE dates (d DATE);
Copy
INSERT INTO dates (d) VALUES 
  ('2024-01-01'::DATE),
  ('2024-01-02'::DATE),
  ('2024-01-03'::DATE),
  ('2024-01-04'::DATE),
  ('2024-01-05'::DATE),
  ('2024-01-06'::DATE),
  ('2024-01-07'::DATE),
  ('2024-01-08'::DATE);
Copy
SELECT d, DAYNAME(d) 
  FROM dates
  ORDER BY d;
Copy
+------------+------------+
| D          | DAYNAME(D) |
|------------+------------|
| 2024-01-01 | Mon        |
| 2024-01-02 | Tue        |
| 2024-01-03 | Wed        |
| 2024-01-04 | Thu        |
| 2024-01-05 | Fri        |
| 2024-01-06 | Sat        |
| 2024-01-07 | Sun        |
| 2024-01-08 | Mon        |
+------------+------------+
Language: English