Adding a interval to datetimestamp from another column
Teradata Teradata Discussion Forums Teradata.com Discussion Forum
Visit Teradata.com
Home       Guidelines    Member List
Welcome Guest ( Login | Register )
        


This online forum is for user-to-user discussions of Teradata products, and is not an official customer support channel for Teradata. If you require direct assistance, please contact Teradata support.


Adding a interval to datetimestamp from... Expand / Collapse
Author
Message
Posted 10/27/2008 9:02:40 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 11/7/2008 5:49:36 PM
Posts: 1, Visits: 7
hi All
is it possible to add a numberic column to a datatime column?
eg:
column 1:begin_date
column 2:add_hours

column 3 = begin_date + interval 'add_hours' hour

how do you do this in teradata?

thanks

Post #13326
Posted 10/27/2008 10:38:49 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 7/10/2009 6:28:52 PM
Posts: 505, Visits: 546
(BEGIN_DATE (TIMESTAMP(0))) + ( ADD_HOURS(INTERVAL HOUR) )
Post #13327
Posted 11/3/2009 7:28:53 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 11/9/2009 3:13:03 PM
Posts: 5, Visits: 11
Can this same thing be done with seconds? I have this problem:

TABLE
Start_timestamp TIMESTAMP
,Duration_time FLOAT


I want to do this:

select
start_timestamp
,start_timestamp + duration_time
from table

I've tried

select
start_timestamp
,start_timestamp + interval duration_time seconds
from table

and

select
start_timestamp
,(start_timestamp(timestamp(0))) +( duration_time(Interval second))
from table

and both get errors.
Post #17224
Posted 11/4/2009 3:55:55 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 2 days ago @ 7:45:03 AM
Posts: 39, Visits: 169
Try this

select
start_timestamp
,start_timestamp + CAST(CAST(duration_time AS DEC(10,6)) AS interval second(4,6))
from table

make sure that FLOAT value should be in range +-9999.999999
Post #17228
Posted 11/4/2009 11:06:12 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 11/9/2009 3:13:03 PM
Posts: 5, Visits: 11
That one worked perfectly. Thanks for the help!
Post #17238
Posted 11/4/2009 12:42:11 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 11/9/2009 3:13:03 PM
Posts: 5, Visits: 11
I spoke a bit too quickly.
It worked at first, but then I ran into an overflow problem. Also, I was wrong in saying the duration field was a float, it's actually an integer.

but, I have values greater than 4 digits in that field so I get an overflow problem. Is "Interval Second(4,6)" as big as that field can get? Can I not have more than 9999.999999 seconds?

If not, I'd imagine I'd have to split up the number of seconds into a time field and then use that, something like

cast(trim(cast(cast(duration_time as decimal(18,6))/60/60 as integer)) || ':' || trim(cast(cast(duration_time as decimal(18,6))/60 as integer)) || ':' || trim(cast(substring ( cast(duration_time as decimal(18,6))/60 from position('.' in cast(duration_time as decimal(18,6))/60) for 3) * 60 as integer)) as time(0)) as Total_Duration

Can I add a time field to a timestamp field?
Post #17241
Posted 11/4/2009 5:46:26 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 11/9/2009 3:13:03 PM
Posts: 5, Visits: 11
I decided to go about this a bit differently and it worked.

Instead of the big long concatenation string, I decided on this statement:

SELECT
,start_timestamp
,cast(START_TIMESTAMP + cast(cast((DURATION_TIME/60) as dec(10,6)) as interval minute(4)) as timestamp(0)) + cast(trim(cast(substring ( cast(DURATION_TIME as decimal(18,6))/60 from position('.' in cast(DURATION_TIME as decimal(18,6))/60) for 3) * 60 as integer)) as interval second(4,6))
FROM
TABLE

This one works fine, even if long.
Post #17246
Posted 11/5/2009 4:29:00 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 11/5/2009 4:40:02 PM
Posts: 717, Visits: 466
Hi keno,
if the duration is less than 864,000,000 seconds:

start_timestamp +
(duration * INTERVAL '0000 00:00:01.000000' DAY TO SECOND)

Dieter
Post #17262
Posted 11/5/2009 4:48:00 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 11/9/2009 3:13:03 PM
Posts: 5, Visits: 11
I knew there had to be an easier option! That one works and makes cleaner code!
Post #17266
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 ( 0 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.


All times are GMT -5:00, Time now is 6:14am

Powered By InstantForum.NET v4.1.4 © 2009
Execution: 0.125. 9 queries. Compression Disabled.