简体   繁体   中英

How to compare timestamp with current time in oracle sql

I have a sql query in oracle. I want to select records which has field "c_time" (format by timestamp) older than current time 5 minutes.

Thanks

我认为典型的方式是:

where c_time < current_timestamp - interval '5' minute

Another alternative is

where c_time < systimestamp - (5/(24*60))

24*60 is used to convert the value in minutes.

Cheers!!

We can also try using the NUMSTODSINTERVAL() function here:

SELECT *
FROM yourTable
WHERE c_time < CURRENT_TIMESTAMP - NUMTODSINTERVAL(5, 'MINUTE');

this will work:

where EXTRACT(year FROM c_time)=EXTRACT(year FROM CURRENT_TIMESTAMP) and 
    EXTRACT(month FROM c_time)=EXTRACT(month FROM CURRENT_TIMESTAMP)
    EXTRACT(day FROM c_time)=EXTRACT(day FROM CURRENT_TIMESTAMP)
    EXTRACT(hour FROM c_time) =EXTRACT(hour FROM CURRENT_TIMESTAMP)
    EXTRACT(minute FROM c_time)-5>EXTRACT(minute FROM CURRENT_TIMESTAMP)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM