时间:2021-07-01 10:21:17 帮助过:370人阅读
--本月第一天: selectdateadd(dd,-day(getdate())+1,getdate()) --本月最后一天: SELECTdateadd(ms,-3,DATEADD(mm,DATEDIFF(m,0,getdate())+1,0)) --上个月第一天: select CONVERT(int, CONVERT(varchar(10),DATEADD(m,-1 ,dateadd(dd,-day(getdate())+1,g
--本月第一天:
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))
附录:http://www.w3school.com.cn/sql/sql_dates.asp