SQLSERVER取当前月第一天和最后一天
--本月第一天:
select dateadd(dd,-day(getdate())+1,getdate())
--本月最后一天:
SELECT dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0))
--上个月第一天:
select CONVERT(int, CONVERT(varchar(10),DATEADD(m,-1 ,dateadd(dd,-day(getdate())+1,getdate())) ,112))
--上个月最后一天:
SELECT CONVERT(int,convert(varchar(10),dateadd(d,-1,dateadd(m,-1,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0))),112))
--本月第一日最后一日
select DATEADD(MM,DATEDIFF(MM,0,GETDATE()),0) AS 本月第一日
,DATEADD(DAY,-1,DATEADD(MM,DATEDIFF(MM,0,GETDATE())+1,0)) 本月最后一日;