t.end_time_ 換成你的時間字段
-- 今天的數據 00:00:00-23:59:59 and t.end_time_ BETWEEN CONVERT(varchar(100), GETDATE(), 23) +' 00:00:00' AND CONVERT(varchar(100), GETDATE(), 23) +' 23:59:59' -- 本周的數據 周一到周日 and t.end_time_> DATEADD(wk, DATEDIFF(wk,0,DATEADD(dd, -1, getdate()) ), 0) and t.end_time_<DATEADD(wk, DATEDIFF(wk,0,DATEADD(dd, -1, getdate()) ), 7) --本月的數據 and datediff(month, t.end_time_,getdate())=0