Search code examples
datecastingtimestamporacle19c

Convert timestamp to date in Oracle 19c without time


I'm coming from db2 and now need to cast a timestamp field to date in Oracle 19c.

Using cast(mytimestampfield as date) it is returning the time too. How to that without return the time?

Testing...it returns 2024-02-28 13:16:42

SELECT cast(SYSTIMESTAMP as date) FROM dual;

I'm looking for : 2024-02-28


Solution

  • In this case you can use truncate:

    TRUNC(cast(SYSTIMESTAMP as date))
    

    See the Oracle documentation for more information

    https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/TRUNC-date.html#GUID-BC82227A-2698-4EC8-8C1A-ABECC64B0E79