本文介绍了我怎样才能找到特定的日子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的日期值 - 12/2011 或 11/2011 (MM/yyyy
)
I have the date value like this - 12/2011 or 11/2011 (MM/yyyy
)
我想找到特定月份的星期日....
I want to find the sundays on the particular month....
例如,如果我选择 01/2012 月份,查询应该给出这样的结果
For Example, If i select the month 01/2012, The query should give the result like this
01
08
15
22
29
以上日期为星期日.
01/2012
月的预期输出
01
08
15
22
29
如何进行查询
需要查询帮助
推荐答案
借助一个数字表(master..spt_values
)
declare @M varchar(7)
set @M = '01/2012'
declare @D datetime
set @D = convert(datetime, '01/'+@M, 103)
set datefirst 7
select dateadd(day, N.Number, @D)
from master..spt_values as N
where N.type = 'P' and
dateadd(day, N.Number, @D) >= @D and
dateadd(day, N.Number, @D) < dateadd(month, 1, @D) and
datepart(weekday, dateadd(day, N.Number, @D)) = 1
这篇关于我怎样才能找到特定的日子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!