Given two datetimes, how can I query, using t-sql, the exact day, hour and minute difference between them?
The difference between February 8th at 7:52 AM and February 14th at 3:34 PM is indeed 6 days, 7 hours, and 42 minutes.
Check out Jeff Moden's outstanding post on time differences for a way to calculate the difference in various formats. He did a great job explaining the concept, I think. Later on in the thread, GSquared has another method for getting the values, and it looks like this:
This query has some problems with edge cases, so beware if your query needs to span more than one year.
answered Feb 14 '11 at 04:48 PM