SQL - Scalar functions - EXTRACT
The EXTRACT function returns a portion of a datetime based on its arguments.
The schema is SYSIBM.
If the argument can be null, the result can be null; if the argument is null, the result is the null value.
If a date expression is a character string, it must be a valid string representation of a date that is not a CLOB. In a Unicode database, if a date expression is a graphic string, it is first converted to a character string before the function is executed.
If a timestamp expression is a character string, it must be a valid string representation of a timestamp that is not a CLOB. In a Unicode database, if a timestamp expression is a graphic string, it is first converted to a character string before the function is executed.
If a time expression is a character string, it must be a valid string representation of a time that is not a CLOB. In a Unicode database, if a time expression is a graphic string, it is first converted to a character string before the function is executed.
If timestamp-expression is a DATE, it is converted to a TIMESTAMP(0) value, assuming a time of exactly midnight (00.00.00).
If a timestamp expression is a character string, it must be a valid string representation of a timestamp or date that is not a CLOB. In a Unicode database, if a timestamp expression is a graphic string, it is first converted to a character string before the function is executed. The string is converted to a TIMESTAMP(6) value.
The data type of the result of the function depends on the part of the datetime value that is specified:
SELECT EXTRACT(MONTH FROM col1) FROM PROJECT;
SELECT EXTRACT(MILLISECONDS FROM col2) FROM PROJECT;
SELECT EXTRACT(MICROSECONDS FROM col2) FROM PROJECT;
SELECT EXTRACT(DECADE FROM col3) FROM PROJECT;
SELECT EXTRACT(MONTH FROM col4) FROM PROJECT;
SELECT EXTRACT(SECONDS FROM col5) FROM PROJECT;
SELECT EXTRACT(MILLISECOND FROM col6) FROM PROJECT;