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)
 Time Subtraction

Author  Topic 

dim
Yak Posting Veteran

57 Posts

Posted - 2010-07-20 : 11:37:02
Hi,

I have a two columns which are varchar and represents time information :
e.g : 05:45:00

I need to subtract these two cloumns to get the time differences.

like : 13:00:00 - 7:00:00 = 06:00:00

I would request if anybody could guide me achieve this task.

Dp

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-07-20 : 12:10:31
[code]select
TimeDiffVarchar =
convert(varchar(8),convert(datetime,'13:00:00')-convert(datetime,'7:00:00'),108),
TimeDiff =
convert(datetime,'13:00:00')-convert(datetime,'7:00:00')[/code]

Results:
[code]TimeDiffVarchar TimeDiff
--------------- -----------------------
06:00:00 1900-01-01 06:00:00.000

(1 row(s) affected)[/code]



CODO ERGO SUM
Go to Top of Page
   

- Advertisement -