Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oracle timestamp without seconds

I have a timestamp(6) column in a table in my database. I would like to do a comparison on it but without considering the seconds part. I know that I can trunc(timestamp) to remove the time and leave the date part. Is there a way I can set the seconds to 0?

I want to do this:

CASE WHEN ARR NOT BETWEEN FROM AND TO THEN 1
     ELSE 0 END "mismatch"

..but get mismatches when the ARR has a seconds part greater than FROM and TO. I dont care about seconds and only want to consider minutes.

Any advice greatly appreciated.

Thanks

like image 756
RNJ Avatar asked Jan 06 '14 13:01

RNJ


People also ask

What is the timestamp format in Oracle?

yyyy-MM-dd HH:mm:ss. 2018-03-5 15:16:0; 2018-03-5 15:16:0 +5:30. yyyy-MM-dd HH.mm.ss. 2018-03-5 15.16.0; 2018-03-5 15.16.0 +5:30. yyyy-MM-dd HH:mm.

Does Oracle timestamp have milliseconds?

Dates do not contain milliseconds, they only go as fine as seconds. You might want to try a timestamp datatype.

How do I find the difference between two dates and seconds in Oracle?

Best Answer A DATE datatype - a DATE datatype yields a difference in DAYS so to get seconds from that you need to * 24 * 60 * 60 == seconds.

What is the difference between current timestamp and Systimestamp?

SYSTIMESTAMP returns current timestamp on database server, while current_timestamp returns current timestamp on client machine. So if your database server is in New York and client box is in California, SYSTIMESTAMP will be 3 hours ahead of CURRENT_TIMESTAMP.


1 Answers

The trunc() function allows you so decide how much of the precision to discard via the optional fmt parameter; the default is to remove all time components, i.e. the equivalent of trunc(x, 'DD'). If you want to only lose the seconds you can use MI:

select systimestamp, trunc(systimestamp, 'MI') from dual;

SYSTIMESTAMP                        TRUNC(SYSTIMESTAMP,'MI')
----------------------------------- ------------------------
06-JAN-14 13.11.33.046920000 +00:00 2014-01-06 13:11:00      

Note that the value returned from trunc is now a DATE, not a TIMESTAMP. If that is an issue - which is may well not be - you can cast it back:

select systimestamp, cast (trunc(systimestamp, 'MI') as timestamp) from dual;

SYSTIMESTAMP                        CAST(TRUNC(SYSTIMESTAMP,'MI')ASTIMESTAMP)
----------------------------------- -----------------------------------------
06-JAN-14 13.14.43.270506000 +00:00 2014-01-06 13:14:00.000   
like image 160
Alex Poole Avatar answered Sep 28 '22 14:09

Alex Poole