1.取月初的时间
--getdate() :2012/05/08 19:29:00
select convert(varchar,dateadd(day,-day(getdate())+1,getdate()),111) --结果:2012/05/08
2.取月末时间
select convert(varchar,dateadd(day,-day(getdate()),dateadd(month,1,getdate())),111) --结果集:2012/05/31
3.取某一个月的天数
select datediff(day,dateadd(day,-day(getdate()),getdate()),dateadd(day,-day(getdate()),dateadd(month,1,getdate()))) ---31
可将getdate()设为参数,想求几月的天数,则将本月的随便一个日期替换,如想查2月份的,则
select datediff(day,dateadd(day,-day('20120201'),'20120201'),dateadd(day,-day('20120201'),dateadd(month,1,'20120201'))) --29
来源:https://www.cnblogs.com/hlfei/p/3778262.html