- Categories:
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 thedayofweek
part. SeeEXTRACT for an example.
Syntax¶
DAYNAME(<date_or_timestamp_expr>)
Copy
Arguments¶
date_or_timestamp_expr
A date or a timestamp, or an expression that can be evaluated to a date or a timestamp.
Returns¶
Returns a value of VARCHAR data type.
Examples¶
Use theTO_DATE function to get the abbreviation for the day of the week of April 1, 2024:
SELECTDAYNAME(TO_DATE('2024-04-01'))ASDAY;
Copy
+-----+| DAY ||-----|| Mon |+-----+
Use theTO_TIMESTAMP_NTZ function to get the abbreviation for the day of the week of April 2, 2024:
SELECTDAYNAME(TO_TIMESTAMP_NTZ('2024-04-02 10:00'))ASDAY;
Copy
+-----+| DAY ||-----|| Tue |+-----+
Get the abbreviation for the day of the week for each day from January 1, 2024, to January 8, 2024:
CREATEORREPLACETABLEdates(dDATE);
Copy
INSERTINTOdates(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
SELECTd,DAYNAME(d)FROMdatesORDERBYd;
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 |+------------+------------+