to get the difference between two dates we will can use DateDiff function in sql server
declare @start_time datetime ,@end_time datetime
set @start_time = '11/12/2012 12:05:04'
set @end_time = '11/12/2012 12:07:27'
select DATEDIFF(SECOND, @start_time, @end_time) AS SecondDiff
Result will be 143 seconds
in the above code snippet we had declared the starttime and endtime
By using the DateDiff function we got the diffrence between two dates in seconds
these are some other formats of DateDiff function
SELECT DATEDIFF(DAY, GETDATE(), GETDATE() + 1) AS DayDiff
SELECT DATEDIFF(MINUTE, GETDATE(), GETDATE() + 1) AS MinuteDiff
SELECT DATEDIFF(SECOND, GETDATE(), GETDATE() + 1) AS SecondDiff
SELECT DATEDIFF(WEEK, GETDATE(), GETDATE() + 1) AS WeekDiff
SELECT DATEDIFF(HOUR, GETDATE(), GETDATE() + 1) AS HourDiff
Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are
Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator