Recently I wanted to find the time between 2 datetimes, but I wanted to exclude weekends. To further complicate matters, I wanted to know hours, not just days.
The "standard" way to do stuff like this is to build out a calendar table that has every date for the next 50 years, along with info like "IsWeekend" or "IsHoliday".
But I found some snippets around that I hoped to use to my advantage, and what I came up with works very well:
DECLARE @start DATETIME DECLARE @end DATETIME SET @start = '3/7/08 12:50 pm' SET @end = '3/11/08 1:50 am' SELECT (DateDiff(hh, @start, @end) - DateDiff(ww, @start, @end)*2*24)/24.0
Remember Me
Powered by: newtelligence dasBlog 1.9.6264.0
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
E-mail
Theme design by Jelle Druyts