EXTRACT (Lakehouse v1)
Extrait la partie indiquée d’une date, d’une heure ou d’un horodatage.
Voir aussi : DATE_PART
Syntaxe SQL
Section intitulée « Syntaxe SQL »EXTRACT( YEAR | QUARTER | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND | DOW | DOY FROM <date_or_time_expr> )- DOW : jour de la semaine.
- DOY : jour de l’année.
Type de retour
Section intitulée « Type de retour »Entier.
Exemples SQL
Section intitulée « Exemples SQL »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 MondaySELECT EXTRACT(DOW FROM NOW());
extract(dow from now())|-----------------------+ 1|
-- October 16, 2023, is the 289th day of the yearSELECT 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|