EXTRACT in Teradata

You can extract YEAR, MONTH, DAY, HOUR, MINUTE, TIMEZONE_HOUR, TIMEZONE_MINUTE, SECOND from the input date/time.

These are the examples for the EXTRACT function with CURRENT_DATE or CURRENT_TIME as input.

 EXTRACT (MINUTE FROM CURRENT_TIME) 

 EXTRACT (SECOND FROM CURRENT_TIME) 

 EXTRACT (HOUR FROM CURRENT_TIME) 

 EXTRACT (DAY FROM CURRENT_DATE) 

 EXTRACT (YEAR FROM CURRENT_DATE) 

 EXTRACT (MONTH FROM CURRENT_DATE) 


Note:
While you give the date/time as input, please adhere to the syntax and date logic.

For example,

 
SELECT EXTRACT (DAY FROM ‘99-02-18’) 

Result: Error . (Not a correct ANSI format)


The correct format (YYYY-MM-DD) will be,

 
SELECT EXTRACT (DAY FROM ‘2012-02-01’) 

Result: 01


The following code will throw error, since its violating date logic.
 
SELECT EXTRACT (DAY FROM ‘2012-02-31’) 

Result: Error