Oracle equivalent to SQL Server DATEPART

Raj More picture Raj More · May 12, 2011 · Viewed 75.3k times · Source

We need to get the HOUR out of a DATETIME column (expecting values from 0 to 23 to be returned).

Is there an Oracle equivalent of the SQL Server DATEPART function?

Answer

a_horse_with_no_name picture a_horse_with_no_name · May 12, 2011

An alternative is the EXTRACT function which is an ANSI standard and also works on other DBMS, but it also requires the use of current_timestamp (also ANSI) instead of sysdate

SELECT extract(hour from current_timestamp) 
FROM dual