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)))

 
上一篇:DOM4J案例详解(添加 ,查询 ,删除 ,保存)


下一篇:ImportError: No localization support for language ‘eng’ in python