Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to get all Saturday of a month?

Author  Topic 

Mits
Starting Member

48 Posts

Posted - 2005-09-10 : 09:51:39
Hi everyone,

I am stuck on a bit of problem. i need a stored procedure or a function that returns me the dates of every saturday in a given month that i will pass in.

Mits

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-09-10 : 10:21:57
There is a lot of ways to do this (some more efficient than others). Here's one of them:

declare @dt_in datetime
set @dt_in = getdate()

select dt
from (
select dateadd(day, n, dateAdd(month, datediff(month,0,@dt_in),0)) dt
from (
select n1+n2+n3+n4+n5 n
from (select 0 n1 union select 1) n1
cross join (select 0 n2 union select 2) n2
cross join (select 0 n3 union select 4) n3
cross join (select 0 n4 union select 8) n4
cross join (select 0 n5 union select 16) n5
--order by 1
) a
) a
where dateName(weekday,dt) = 'Saturday'
and datediff(month, dt, @dt_in) = 0
order by dt


Be One with the Optimizer
TG
Go to Top of Page

Mits
Starting Member

48 Posts

Posted - 2005-09-12 : 04:08:01
thanks TG, it works
Go to Top of Page
   

- Advertisement -