Currently I'm using MyTimeStampField-TRUNC(MyTimeStampField)
to extract the time part from a timestamp column in Oracle.
SELECT CURRENT_TIMESTAMP-TRUNC(CURRENT_TIMESTAMP) FROM DUAL
This returns
+00 13:12:07.100729
This works OK for me, to extract the time part from a timestamp field, but I'm wondering if there is a better way (may be using a built-in function of ORACLE) to do this?
EXTRACTTIMES() Extract list of Time values within textual value. Returns a list of Time values within the textual value. Includes specific times, times written in prose, and relative times, such as “tomorrow at 3pm”, “one hour from now”, and so on.
However, datepart() function works in SQL Server, Oracle, and Azure SQL databases only. For other database management servers such as PostgreSQL and MYSQL, we can use functions like EXTRACT().
Purpose. The TRUNC (number) function returns n1 truncated to n2 decimal places. If n2 is omitted, then n1 is truncated to 0 places. n2 can be negative to truncate (make zero) n2 digits left of the decimal point.
What about EXTRACT() function?
You could always do something like:
select TO_DATE(TO_CHAR(SYSDATE,'hh24:mi:ss'),'hh24:mi:ss') from dual
I believe this will work with timestamps as well.
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