sql server中输入一个年.月,求出这个月的第一个星期天是几号,这个月共多少天

来源:互联网 发布:数据分析 入门书籍 编辑:程序博客网 时间:2024/05/01 13:48
declare @YearMonth varchar(20)
set @YearMonth = '2007.12'

declare @startingDate datetime
 set @startingDate = substring(@YearMonth,1,4) + '-01-'+ substring(@YearMonth,6,2)
SELECT Day(DATEADD(dd,-(DATEPART(dw, @startingDate ) - 7),@startingDate )) as FirstSunday ,
       DAY(DATEADD(d, -DAY(DATEADD(m,1,@startingDate)),
       DATEADD(m,1,@startingDate))) as DayNum
原创粉丝点击