Sql server: Get difference in Day, Hour, Minute and second between two dates | ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

Sql server: Get difference in Day, Hour, Minute and second between two dates

In this article I am going to explain how to find difference between two dates in day, hour, minute and second using sql server.

Implementation:
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

 Output:

Sql server: Get difference in Day, Hour, Minute and second between two dates




Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget