I need to get a list of all Saturday dates in a given year.
我需要获得给定年份中所有星期六日期的列表。
I've seen an oracle post that goes against a table that had "fiscal calendar table" but I haven't been able to succeed in converting it nor do I have a table that contains a set of dates I want to investigate.
我已经看到一个oracle帖子违反了一个有“财政日历表”的表,但是我无法成功转换它,也没有一个包含一组我想调查的日期的表。
SELECT DATE DATES,TO_CHAR(DATE,'DAY') DAYS FROM FISCAL_CALENDAR
WHERE DATE_YEAR = 2009 AND
DATE BETWEEN TRUNC(SYSDATE,'YEAR') AND
ADD_MONTHS(TRUNC(SYSDATE,'YEAR'),12) -1 AND
TRIM(TO_CHAR(DATE,'DAY')) = 'SUNDAY'
was the Oracle (it was for Sunday and 2009 eg)
是Oracle(这是周日和2009年的例子)
Much thanks. -Tom
非常感谢。 -Tom
2 个解决方案
#1
16
for the year 2010 you can do this
对于2010年,你可以做到这一点
declare @d datetime
select @d = '20100101' --'20090101' if you want 2009 etc etc
select dateadd(dd,number,@d) from master..spt_values
where type = 'p'
and year(dateadd(dd,number,@d))=year(@d)
and DATEPART(dw,dateadd(dd,number,@d)) = 7
#2
-1
declare @d datetime select @d = '20100101' --'20090101' if you want 2009 etc etc
声明@d datetime select @d ='20100101' - '20090101'如果你想要2009等等
select dateadd(dd,number,@d) from master..spt_values where type = 'p' and datename(weekday, (dateadd(dd, number, @d))) in ('Saturday', 'Tuesday' /* Specify Day Name */)
从master..spt_values中选择dateadd(dd,number,@ d),其中type ='p'和datename(工作日,(dateadd(dd,number,@ d)))('Saturday','Tuesday'/ *指定日名* /)
#1
16
for the year 2010 you can do this
对于2010年,你可以做到这一点
declare @d datetime
select @d = '20100101' --'20090101' if you want 2009 etc etc
select dateadd(dd,number,@d) from master..spt_values
where type = 'p'
and year(dateadd(dd,number,@d))=year(@d)
and DATEPART(dw,dateadd(dd,number,@d)) = 7
#2
-1
declare @d datetime select @d = '20100101' --'20090101' if you want 2009 etc etc
声明@d datetime select @d ='20100101' - '20090101'如果你想要2009等等
select dateadd(dd,number,@d) from master..spt_values where type = 'p' and datename(weekday, (dateadd(dd, number, @d))) in ('Saturday', 'Tuesday' /* Specify Day Name */)
从master..spt_values中选择dateadd(dd,number,@ d),其中type ='p'和datename(工作日,(dateadd(dd,number,@ d)))('Saturday','Tuesday'/ *指定日名* /)