Well here's one (EXCEEDINGLY HORRIBLE) way to do it.DECLARE @startDate DATETIMEDECLARE @endDate DATETIMESET @startDate = '01/01/2011 17:00'SET @endDate = '03/02/2011 01:30'select datediff(ss,@startDate,@endDate)/3600.0 --StartDateEveningStartsDECLARE @startDateEv DATETIME SET @startDateEv = DATEADD(DAY, DATEDIFF(DAY, '19000101', @startDate), '19000101') SET @startDateEv = DATEADD(HOUR, 20, @startDateEv)DECLARE @endDateMorning DATETIME SET @endDateMorning = DATEADD(HOUR, 12, @startDateEv)DECLARE @adjustedEndDate DATETIME SET @adjustedEndDate = DATEADD(DAY, DATEDIFF(DAY, '19000101', @endDateMorning), '19000101') + DATEADD(DAY, -DATEDIFF(DAY, '19000101', @endDate), @endDate) SELECT @startDateEv, @endDateMorning, @adjustedEndDateSELECT ((DATEDIFF(DAY, @startDate, @endDate) - 1 )* 12 * 60 * 60 -- Whole Days of darkness! + DATEDIFF( SECOND , CASE WHEN @startDate > @startDateEv THEN @startDate ELSE @startDateEv END , CASE WHEN @adjustedEndDate < @endDateMorning THEN @adjustedEndDate ELSE @endDateMorning END )) / 3600
THis is more of a joke than anything else but I think it generates the right answer.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION