gram77
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)?
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
select systimestamp + interval'0 0:33:44.517948000' day to second from dual
* You can't add
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wasim_Haider:
what does "day to second" part of the select statement tell oracle?
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.
Day to second
Year to Month
Only these interval can be added with timestamp. Otherwise, you can subtract from one timestamp to another.
Thanks.
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
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
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
ASKER
Wasim_Haider:
but what format will be for -05:00?
but what format will be for -05:00?
Perhaps, it is time zone. What do you want by using to_timestamp function?
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.
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
ASKER
Excellent!
select systimestamp a0, systimestamp+(1/24) a1 from dual; -- 1 hour
select systimestamp a0, systimestamp+(1/24/60) a1 from dual; -- 1 minute
etc.