I have a table containing some datetime columns, now I want to get the timespan/interval between two columns in seconds (as int):
declare @Sessions TABLE
(
[session_id] [int] not null,
[start] [datetime] not null,
[end] [datetime] not null
)
insert into @Sessions([session_id], [start], [end])
values (1, '01.04.2012 08:15:05', '01.04.2012 08:16:40');
select [session_id], [end]-[start] as 'duration'
from @Sessions
What I get is a datetime like interval type: eg. 1900-01-01 00:01:35.000.
What I want is the timespan in seconds: eg. 95s.
Parsing the String should not be an option as I suppose that there’s an easy to use function for that – deeply hidden in the msdn documentation, which I haven’t found yet.
So, how to get those time intervals as int in seconds?
Change last select as
I have tried the same below using table instead of table variable: