EXTRACT

Extracts specified components from a given datetime.

Syntax

EXTRACT (unit FROM dateobj)

Arguments

  • dateobj: a valid date, datetime, time, or parsable date string

DATE_ADD

Return Type

Integer

Examples

SELECT EXTRACT(YEAR_MONTH FROM "2010-04-02 01:23:54");
+------------------------------------------------+
| EXTRACT(YEAR_MONTH FROM "2010-04-02 01:23:54") |
+------------------------------------------------+
|                                         201004 |
+------------------------------------------------+
SELECT EXTRACT(MICROSECOND FROM "2010-04-02 01:23:54.567");
+-----------------------------------------------------+
| EXTRACT(MICROSECOND FROM "2010-04-02 01:23:54.567") |
+-----------------------------------------------------+
|                                              567000 |
+-----------------------------------------------------+

Last modified: May 31, 2023

Was this article helpful?