# total time difference between more than two dates

• Because of the leap year subtraction problem, it won't work if one of the dates is before, and one is after, 29 Feb in a leap year, and the two are in different years. I'm sure it could be corrected for, but I'm not sure it's worth it.

If it were sticking to days, like yours, it would work. But adding in months and years breaks it.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

• Humorous, entertaining and very informative. Thanks!:)

• I think that was the longest and most comprehensive reply I've ever seen on here 🙂 Shame it wasn't used 🙁 Hopefully when someone else asks the same question they'll search the forums and at least find lots of information in Jeff's answer!

• Thanks folks. I really appreciate the feedback especially on a long one like that.

--Jeff Moden

RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

Change is inevitable... Change for the better is not.

Helpful Links:
How to post code problems
How to Post Performance Problems
Create a Tally Function (fnTally)

• this works for me:

SET @StartDate = (Select '2013-07-19 12:20:07.097')

Set @EndDate = (SELECT '2013-07-19 15:02:38.000')

SET @RESULT = (SELECT 'Starts in: ' + STR(FLOOR(CAST(@newDate-@RunDate AS FLOAT)),1) + ' days '

+ convert(varchar,datepart(hour,@EndDate-@StartDate)) + ' hrs '

+ convert(varchar,datepart(minute,@EndDate-@StartDate)) + ' mins')

Result is: 'Starts in: 0 days 2 hrs 42 mins'

Viewing 5 posts - 16 through 19 (of 19 total)

You must be logged in to reply to this topic. Login to reply