You are viewing an older version of this section. View current production version.
Join the MemSQL Community Today
Get expert advice, develop skills, and connect with others.

EXTRACT

Extracts specified components from a given datetime.

Syntax

EXTRACT (unit FROM dateobj)

Arguments

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

Unit specifies the components to be extracted. See DATE_ADD for a description of valid units.

Return Type

Integer

Examples

memsql> select EXTRACT(YEAR_MONTH from "2010-04-02 01:23:54");
+------------------------------------------------+
| EXTRACT(YEAR_MONTH from "2010-04-02 01:23:54") |
+------------------------------------------------+
|                                         201004 |
+------------------------------------------------+

memsql> select EXTRACT(MICROSECOND from "2010-04-02 01:23:54.567");
+-----------------------------------------------------+
| EXTRACT(MICROSECOND from "2010-04-02 01:23:54.567") |
+-----------------------------------------------------+
|                                              567000 |
+-----------------------------------------------------+