EXTRACT: Obtaining a Datetime Field From Date/Time/Timestamp

How to:

The EXTRACT function can be used to obtain the year, month, day of month, hour, minute, second, millisecond, or microsecond component of a date, time, or timestamp value.


Top of page

x
Syntax: How to Obtain a Datetime Field From a Date, Time, or Timestamp
EXTRACT(field FROM arg)

where:

arg

Date, time, or timestamp

Is the input argument.

field

Is the datetime field of interest. Possible values are YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, MILLISECOND and MICROSECOND.

This function returns an integer value.

Note:



Example: Obtaining a Datetime Field From a Date, Time, or Timestamp

EXTRACT returns the components of a date, time, or timestamp. This example,

EXTRACT(YEAR FROM '2000-01-01')

returns 2000.

This example,

EXTRACT(HOUR FROM '11:22:33')

returns 11.

This example,

EXTRACT(MICROSECOND FROM '2000-01-01 11:22:33.456789')

returns 456,789.


iWay Software