Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to calculate time difference past midnight!

Status
Not open for further replies.

SimonBurrell

Technical User
Aug 7, 2002
8
AU
I hope this helps someone when trying to work out how to calculate the time difference when the endtime is the next day.

I finally worked it out (thanks to the legendary Dr Bull).

Code:
/* This returns an output in minutes. If whole hours is the result you want - change the 720 (minutes) to 12 (hours) and change the datediff datepart to hh (hours)*/

SELECT TimeDiff =
  	CASE
	WHEN  EndTime < Starttime  THEN (720 -((datediff(mi,EndTime,StartTime )) - 720)) 
	WHEN EndTime > Starttime THEN(datediff(mi, StartTime, EndTime))
          END
FROM YourTable

Regards

Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top