取出某个月有几天
取出某个月有几天
--取出这个月有几天 SELECT 32-DAY(GETDATE()+(32-DAY(GETDATE()))) --取出上个月有几天 select day(getdate()-day(getdate())) --取出某个月有几天 SELECT 32-DAY(CAST('2000-02-22' AS DATETIME)+(32-DAY(CAST('2000-02-22' AS DATETIME))))
取月初月末和月份间隔
--1.取月初月末 declare @startdate datetime select @startdate=dateadd(dd,-datepart(dd,getdate())+1,getdate()) select SUBSTRING(Convert(varchar(100),@startdate ,23),1,10) declare @enddate datetime select @enddate=dateadd(dd,-datepart(dd,getdate()),dateadd(mm,1,getdate())) select SUBSTRING(Convert(varchar(100),@enddate ,23),1,10) --2.取间隔一个月 declare @startdate datetime select @startdate= dateadd(MM,-1,dateadd(dd,-datepart(dd,getdate())+1,getdate())) select SUBSTRING(Convert(varchar(100),@startdate ,23),1,10) declare @enddate datetime select @enddate=dateadd(MM,-1,dateadd(dd,-datepart(dd,getdate())+1,dateadd(mm,1,getdate()))) select SUBSTRING(Convert(varchar(100),@enddate ,23),1,10)