April 14, 2008 at 11:48 am
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
April 14, 2008 at 1:27 pm
Humorous, entertaining and very informative. Thanks!:)
April 18, 2008 at 4:24 am
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!
April 18, 2008 at 5:53 am
Thanks folks. I really appreciate the feedback especially on a long one like that.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 18, 2013 at 7:37 pm
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