create function dbo.DateRow(@DATEIN DateTime)
returns int
as
begin
declare @RETVAL int
declare @THEDAY DateTime
-- truncate supplied date for the day in question
set @THEDAY=cast(convert(varchar(11),@DATEIN,113) as DateTime)
set @RETVAL=
case when
@DATEIN < dateadd(Hour,4,@THEDAY) or
@DATEIN >= dateadd(Hour,20,@THEDAY) then...