EXTRACT
Retrieves the designated portion of a date, time, or timestamp.
See also: DATE_PART
SQL Syntax
EXTRACT( YEAR | QUARTER | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND | DOW | DOY FROM <date_or_time_expr> )
- DOW: Day of the Week.
- DOY: Day of Year.
Return Type
Integer.
SQL Examples
SELECT NOW();
now() |
---------------------+
2023-10-16 02:09:28.0|
SELECT EXTRACT(DAY FROM NOW());
extract(day from now())|
-----------------------+
16|
-- October 16, 2023, is a Monday
SELECT EXTRACT(DOW FROM NOW());
extract(dow from now())|
-----------------------+
1|
-- October 16, 2023, is the 289th day of the year
SELECT EXTRACT(DOY FROM NOW());
extract(doy from now())|
-----------------------+
289|
SELECT EXTRACT(MONTH FROM TO_DATE('2022-05-13'));
extract(month from to_date('2022-05-13'))|
-----------------------------------------+
5|
Last modified June 12, 2024 at 9:53 PM EST: updating datetime functions (f087f54)