SQLSERVER取当前月第一天和最后一天
程序员文章站
2024-01-30 15:52:42
...
--本月第一天: 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
上一篇: PHP可以开发客户端么