Computed Column

SQL 2008

I have 2 Time(7) fields, Stime and Etime, I need a computed column (Hours) that calculates the difference between those 2 fields, only hours and minutes. Thank you

June 30th, 2015 3:30pm

create table test (Stime Time(7), Etime Time(7),  DiffInMinutes as datediff(minute,Stime ,Etime) )

insert into test values ('10:35:45.3370000', cast(getdate() as time(7)))

select * from test

drop table test

  • Marked as answer by joshukov 11 hours 16 minutes ago
Free Windows Admin Tool Kit Click here and download it now
June 30th, 2015 3:40pm

Hello!

declare @tab table
(
Stime time,
Etime time,
CumputedColumn as CONVERT(char(5), DATEADD(MINUTE, datediff(minute, stime, etime), ''), 114)
)

insert into @tab values
('05:10:30', '08:23:45')

select * from @tab

June 30th, 2015 3:50pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics