Teradata Extract function
The extract function in teradata extracts year, month, day, hour, minute, or second from a DateTime or Interval values. The date format must match 'YYYY-MM-DD' to extract year, month, or day. And the time format must match 'HH:MI:SS.SSSSS' to extract hour, minute, or second. Actually, extract function returns numerical values.
See the syntax of EXTRACT function.
EXTRACT (YEAR FROM date_value) EXTRACT (MONTH FROM date_value) EXTRACT (DAY FROM date_value) EXTRACT (HOUR FROM time_value) EXTRACT (MINUTE FROM time_value) EXTRACT (SECOND FROM time_value)
See the following examples of teradata extract function to understand.
Example 1:
The following statement extracts YEAR from current date.
SELECT EXTRACT (YEAR FROM CURRENT_DATE);
Result:
2019
Example 2:
The following statement extracts month from date string.
SELECT EXTRACT (MONTH FROM '2000-02-12');
Result:
02
Example 3:
The following statement gives an error. Because the date format is wrong.
SELECT EXTRACT (MONTH FROM '96-02-12');
Example 4:
The following statement extracts hours from current date.
SELECT EXTRACT (HOUR FROM CURRENT_TIME);
Result:
09
Example 5:
The following statement extracts minutes from date string.
SELECT EXTRACT (MINUTE FROM '21:45:12.3');
Result:
45
See also
Was this article helpful?
