How to Add 10 Seconds in Current_Timestamp SQL ( Oracle )

How to add 10 seconds in current_timestamp SQL ( Oracle )

In Oracle, if you want a timestamp as the result, rather than a date (a date always includes the time to the second, though, so you may just want a date), you'd want to add an interval to the timestamp. There are various ways to construct an interval-- you can use an interval literal

select current_timestamp + interval '10' second
from dual

or you could use the numtodsinterval function

select current_timestamp + numToDSInterval( 10, 'second' )
from dual

Oracle: how to add minutes to a timestamp?

All of the other answers are basically right but I don't think anyone's directly answered your original question.

Assuming that "date_and_time" in your example is a column with type DATE or TIMESTAMP, I think you just need to change this:

to_char(date_and_time + (.000694 * 31))

to this:

to_char(date_and_time + (.000694 * 31), 'DD-MON-YYYY HH24:MI')

It sounds like your default date format uses the "HH" code for the hour, not "HH24".

Also, I think your constant term is both confusing and imprecise. I guess what you did is calculate that (.000694) is about the value of a minute, and you are multiplying it by the number of minutes you want to add (31 in the example, although you said 30 in the text).

I would also start with a day and divide it into the units you want within your code. In this case, (1/48) would be 30 minutes; or if you wanted to break it up for clarity, you could write ( (1/24) * (1/2) ).

This would avoid rounding errors (except for those inherent in floating point which should be meaningless here) and is clearer, at least to me.

Oracle: add milliseconds to my timestamp object

You add time to a timestamp by adding an interval. Intervals can go down to seconds only, but an interval of 0.001 seconds is a milliseconds interval which you can multiply with the desired value. E.g:

select systimestamp + interval '0.001' second * :millisecs from dual;

How to insert a timestamp in Oracle?

insert
into tablename (timestamp_value)
values (TO_TIMESTAMP(:ts_val, 'YYYY-MM-DD HH24:MI:SS'));

if you want the current time stamp to be inserted then:

insert
into tablename (timestamp_value)
values (CURRENT_TIMESTAMP);

Oracle: add milliseconds to my timestamp object

You add time to a timestamp by adding an interval. Intervals can go down to seconds only, but an interval of 0.001 seconds is a milliseconds interval which you can multiply with the desired value. E.g:

select systimestamp + interval '0.001' second * :millisecs from dual;

Add Seconds to Timestamp from another Timestamp

Try:

timestamp2  + (extract (second from timestamp1)/86400) 


Related Topics



Leave a reply



Submit