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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateDiff and then SUM 1

Status
Not open for further replies.

Cpreston

MIS
Mar 4, 2015
969
0
16
GB
Hi

I have used the below code to calculate the difference between 2 datetime fields. The result is in seconds but I would like it to display hours and minutes and seconds if possible. I have tried SUM and also converet with just Time instead of datetime. Any ideas please

DATEDIFF(MINUTE,CONVERT(DATETIME,dbo.WTTReportHeader.StartTime,101),CONVERT(DATETIME,dbo.WTTReportHeader.EndTime,101)) as Timediff



Capture_ybygoz.jpg
 
As in my reply to your previous question:
Code:
SELECT LEFT(CONVERT(TIME, DATEADD(ss, DATEDIFF(ss,dbo.WTTReportHeader.StartTime, dbo.WTTReportHeader.EndTime),0)),8) 
FROM YourTable

Borislav Borissov
VFP9 SP2, SQL Server
 
Hi bborissov
Thanks for the post, I was trying to use your code from the previous post but could not quite get it right with the convert and then the datediff.
Your line of code worked first time so thank you for your help, really appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top