Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to add two columns with datetime and int type

Author  Topic 

sql-buzz
Starting Member

7 Posts

Posted - 2008-07-24 : 17:50:27

Hi,
I have a datetime column called StartTime with value such as '2/7/2008 1:02:00 PM'
The other column which is called Duration is of int type.
how can I add the int values from Duration column to the StartTime column and get the result as a third column called EndTime.

For example:
StartTime = '2/7/2008 1:02:00 PM'
Duration = 20
EndTime= '2/7/2008 1:02:20 PM'

something like this:
select StartTime, Duration, DateAdd(StartTime, Duration) as EndTime from table1;

Thanks

sql-buzz
Starting Member

7 Posts

Posted - 2008-07-24 : 18:47:42
Hey huys,
i think I got the answer. if anybody has a better solution just let me know..

select duration,Startdate, dateadd(second,duration,StartDate) as 'Timetaken'
from table1
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-07-24 : 18:47:43
[code]select StartTime, Duration, DateAdd(ss,Duration,StartTime) as EndTime from table1;[/code]

CODO ERGO SUM
Go to Top of Page
   

- Advertisement -