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?
The function works with a set of two arguments, an input date and the name of the part that has to be extracted from it. However, datepart() function works in SQL Server, Oracle, and Azure SQL databases only.
The DATEPART() function returns a specified part of a date. This function returns the result as an integer value.
In short, both Oracle and SQL Server are powerful RDBMS options. Although there are a number of differences in how they work “under the hood,” they can both be used in roughly equivalent ways. Neither is objectively better than the other, but some situations may be more favorable to a particular choice.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With