declare
@dtEnd datetime =
case
when cast(GetDate() as TIME) < '6:00' then DateAdd(Hour, -6, dateadd(Day, DateDiff(Day, 0, GetDate()), 0)) -- 6pm yesterday
when cast(GetDate() as TIME) < '18:00' then DateAdd(Hour, 6, dateadd(Day, DateDiff(Day, 0, GetDate()), 0)) -- 6am today
else DateAdd(Hour, 18, dateadd(Day, DateDiff(Day, 0, GetDate()), 0)) -- 6pm today
end
declare
@dtStart datetime = dateadd(Hour, -12, @dtEnd)
select
<whatever>
from
MyTable
where
MyDatetime between @dtStart and @dtEnd
=================================================
We are far more concerned about the desecration of the flag than we are about the desecration of our land. -Wendell Berry