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,month,月末,dateadd,201902,SQL,查询,SELECT 来源: https://www.cnblogs.com/Bill-Lee/p/11238052.html