Product Documentation

SQL Reference Guide

Previous Topic

Next Topic

EXTRACT SQL Function

Syntax

EXTRACT(date_time_field FROM date_time_expression)

date_time_field ::

| SECOND

| MINUTE

| HOUR

| DAY

| MONTH

| YEAR

Description

The scalar function EXTRACT returns the a date and time field from a date and time expression.

Example

SELECT SYSDATE() ,EXTRACT(MONTH FROM SYSDATE()) 'month'

FROM admin.syacalctable;

SYSDATE MONTH

---------- -------

11/21/2004 11

Details

The date_time_expression can evaluate to a TIME, DATE or TIMESTAMP data type.

The date_time_field and date_time_expression must be compatible.

date_time_expression is a TIME, DATE or TIMESTAMP from which EXTRACT returns the specified date_time_field.

date_time_field keywords that specify the field to be extracted from the date_time_expression.

  • SECOND specifies that second part has to be extracted from the date_time_expression.
  • MINUTE specifies that minute part has to be extracted from the date_time_expression.
  • HOUR specifies that hour part has to be extracted from the date_time_expression.
  • DAY specifies that day part has to be extracted from the date_time_expression.
  • MONTH specifies that month part has to be extracted from the date_time_expression.
  • YEAR specifies that year part has to be extracted from the date_time_expression.

Note: SQL-99 and ODBC compatible

TOCIndex