SQL获取本周、本月、本年时间段值

-- 获取本周时间段值  
SELECT   DATEADD (WK, DATEDIFF (WK, 0 , GETDATE ()), - 1 )
SELECT   DATEADD (WK, DATEDIFF (WK, 0 , GETDATE ()), 6 )
-- 获取本月时间段值
SELECT   DATEADD (MM, DATEDIFF (MM, 0 , GETDATE ()), 0 )
SELECT   DATEADD (MS, - 3 , DATEADD (MM, DATEDIFF (M, 0 , GETDATE ()) + 1 , 0 ))
-- 获取本年时间段值
SELECT   DATEADD (YY, DATEDIFF (YY, 0 , GETDATE ()), 0 )
SELECT   DATEADD (MS, - 3 , DATEADD (YY, DATEDIFF (YY, 0 , GETDATE ()) + 1 , 0 ))

你可能感兴趣的:(sql)