DateDiff vs DateAdd

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

create table #datetmp (
    datea datetime not null,
    dateb datetime not null);
insert into #datetmp values ('2015-01-01 00:30', '2015-01-01 01:30');
insert into #datetmp values ('2015-01-01 00:05', '2015-01-01 00:15');
insert into #datetmp values ('2015-01-01 00:55', '2015-01-01 01:05');
insert into #datetmp values ('2015-01-01 00:59', '2015-01-01 12:01');

select datea,
       dateb,
       datediff(hour, datea, dateb) as Hours,
       datediff(minute, datea, dateb) as Minutes
       
from #datetmp

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results