How Do I Get The Minute Difference Between 2 Times In T Sql?
How do I get the 'minutes' difference between 2 times in T SQL? I tried DATEDIFF, but it obviously wants dates. This would be the difference in minutes between 2 times in a day.
Solution 1:
DateDiff not only work with Date datatype it even accepts TIME datatype.
Even if your datatype is nvarchar it will work but it should be a valid time.
Simple Demo
createtable time_test(a nvarchar(50),b nvarchar(50))
insert time_test values ('4:00 PM','4:30 PM')
select datediff(minute,a,b) from time_test --30Solution 2:
I think DATEDIFF would be your best option. I know you are looking for the difference in time within the same day, but couldn't you just pass DATEDIFF two DateTime types with the same date, but different times?
// Should return 300
DATEDIFF(mi, '2015-02-19 08:00:00', '2015-02-19 13:00:00')
Solution 3:
This usually works for me:
DATEDIFF(minute, @StarTime, @endTime)
Post a Comment for "How Do I Get The Minute Difference Between 2 Times In T Sql?"