SQL 获取本月第一天,上月第一天

SELECT
DATEADD(mm, DATEDIFF(m, 0, GETDATE()) - 1, 0) AS '上月第一天',
DATEADD(ms, - 3, DATEADD(mm, DATEDIFF(m, 0, GETDATE()), 0)) AS '上月最后一天',
DATEADD(mm, DATEDIFF(m, 0, GETDATE()), 0) AS '本月第一天',
DATEADD(ms, - 3, DATEADD(mm, DATEDIFF(m, 0, GETDATE()) + 1, 0)) AS '本月最后一天',
DATEADD(mm, DATEDIFF(m, 0, GETDATE()) + 1, 0) AS '下月第一天',
DATEADD(ms, - 3, DATEADD(mm, DATEDIFF(m, 0, GETDATE()) + 2, 0)) AS '下月最后一天'

 

你可能感兴趣的