EXTRACT Operator

Description

The EXTRACT operator extracts the values from date-time_argument and then converts the value type into INTEGER.

0 is not allowed in the argument value corresponding to year, month, and day; however, if 0 is inputted in every argument value corresponding to date and time, 0 is returned as an exception.

Syntax

EXTRACT ( field FROM date-time_argument )

 

field :

YEAR

MONTH

DAY

HOUR

MINUTE

SECOND

MILLISECOND

 

date-time_argument :

expression

Example

SELECT EXTRACT(MONTH FROM DATETIME '2008-12-25 10:30:20.123' );

  extract(month  from datetime '2008-12-25 10:30:20.123')

=========================================================

                                                       12

 

SELECT EXTRACT(HOUR FROM DATETIME '2008-12-25 10:30:20.123' );

 extract(hour  from datetime '2008-12-25 10:30:20.123')

=========================================================

                                                       10

 

SELECT EXTRACT(MILLISECOND FROM DATETIME '2008-12-25 10:30:20.123' );

 extract(millisecond  from datetime '2008-12-25 10:30:20.123')

=========================================================

                                                      123

 

SELECT EXTRACT(MONTH FROM '0000-00-00 00:00:00');

 extract(month from '0000-00-00 00:00:00')

==========================================

                                         0