In this article I am going to explain how to find difference between two dates in day, hour, minute and second using sql server.
I want to get difference of two dates in days, hour, minutes and second. To get difference I have use datediff function of sql.
Here is the query that works for me:
DECLARE @startdate datetime , @enddate datetime
SET @startdate = '2017-01-01 9:28:30'
SET @enddate = GETDATE()
SELECT [Days]= DateDiff(DD, @startdate, @enddate)
,[Hours]= DateDiff(HH, @startdate, @enddate) % 24
,[Mins]= DateDiff(MI, @startdate, @enddate) % 60
,[Sec] =DateDiff(SS, @startdate, @enddate) % 60
What do you think about this article?
If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.