sql 查询月初日期
作者:互联网
-- 当月第一天
select dateadd(month, datediff(month, 0, getdate()), 0)
-- 当月最后一天(思路:下月的第一天减去一天)
select dateadd(month, datediff(month, 0, dateadd(month, 1, getdate())), -1)
--取某月第一天:
SELECT CAST((LEFT('201902',4)+'-'+SUBSTRING('201902',5,LEN('201902'))+'-'+'01') AS DATETIME)
--取某月最后一天:
SELECT DATEADD(DAY,-1,DATEADD(MONTH,1,CAST((LEFT('201902',4)+'-'+SUBSTRING('201902',5,LEN('201902'))+'-'+'01') AS DATETIME)))
标签:第一天,--,datediff,dateadd,month,日期,201902,sql,查询 来源: https://www.cnblogs.com/baili-luoyun/p/13358782.html