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 2008 Forums
 Transact-SQL (2008)
 time difference

Author  Topic 

Arun.G
Yak Posting Veteran

81 Posts

Posted - 2010-06-25 : 03:43:35
i have two columns which store intime and outtime as datattype
time(0)

ex:

in_time : 09:00:00
out_time : 18:30:00

now i want to calculate the total_time

the output should be: total_time = 09:30:00


how to to it in sqlserver 2008?

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-25 : 03:53:17

select convert(varchar(8),cast(in_time as datetime)-out_time,108) from table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-06-25 : 03:56:49
quote:
Originally posted by madhivanan


select convert(varchar(8),cast(in_time as datetime)-out_time,108) from table

Madhivanan

Failing to plan is Planning to fail



shouldn't it be out_time - in_time ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-25 : 04:57:30
quote:
Originally posted by khtan

quote:
Originally posted by madhivanan


select convert(varchar(8),cast(in_time as datetime)-out_time,108) from table

Madhivanan

Failing to plan is Planning to fail



shouldn't it be out_time - in_time ?


KH
[spoiler]Time is always against us[/spoiler]




Yes

select convert(varchar(8),cast(out_time as datetime)-in_time,108) from table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -