Link to home
Start Free TrialLog in
Avatar of gram77
gram77Flag for India

asked on

Add hours:minutes:seconds to a timestamp datatype.

How can I add 0 0:17:5.946301000 hours:minutes:seconds:sub-seconds to 0 0:33:44.517948000 (timestamp datatype)?
Avatar of fluglash
fluglash

select systimestamp a0, systimestamp+(1) a1 from dual; -- 1 day
select systimestamp a0, systimestamp+(1/24) a1 from dual; -- 1 hour
select systimestamp a0, systimestamp+(1/24/60) a1 from dual; -- 1 minute
etc.
You can can’t add timestamp to timestamp, but you can add timestamp value as interval with timestamp data field. For example:

select systimestamp + interval'0 0:33:44.517948000' day to second from dual
* You can't add
ASKER CERTIFIED SOLUTION
Avatar of Wasim_Haider
Wasim_Haider
Flag of Bangladesh image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gram77

ASKER

Wasim_Haider:
what does "day to second" part of the select statement tell oracle?
It is the syntax for Interval. Actually there are two type of intervals:
Day to second  
Year to Month

Only these interval can be added with timestamp. Otherwise, you can subtract from one timestamp to another.

Thanks.
Avatar of gram77

ASKER

Wasim_Haider:
why is this statement giving an error:

select to_timestamp('10-MAR-10 06.56.41.642092000 AM -05:00','dd-mon-yy hh:mi:ss:ff AM ')
+ interval'0 0:33:44.517948000' day to second
from dual
Correct is:
select to_timestamp('10-MAR-10 06:56:41.642092000 AM','dd-mon-yy hh:mi:ss:ff AM ')
+ interval'0 0:33:44.517948000' day to second
from dual
Avatar of gram77

ASKER

Wasim_Haider:
but what format will be for -05:00?
Perhaps, it is time zone. What do you want by using to_timestamp function?
Avatar of gram77

ASKER

Yes, it seems to be a time zone, but it does not seem to fit into the to_timestamp model..
Using to_timestamp function, I am able to convert a string into a timestamp and then add a time interval
to the timestamp.
Yes. time zone does not need to fit into the to_timestamp model. Good bye. Nice to talk with you. Thanks
Avatar of gram77

ASKER

Excellent!