Showing posts with label mondays. Show all posts
Showing posts with label mondays. Show all posts

Friday, March 30, 2012

Query Help

I'm trying to find the number of Mondays since 6/1/2005. Any suggestions?
THanks"Arul" <Arul@.discussions.microsoft.com> wrote in message
news:199031D2-BCCC-43EE-91F5-D5A20E47068C@.microsoft.com...
> I'm trying to find the number of Mondays since 6/1/2005. Any suggestions?
> THanks
http://www.aspfaq.com/show.asp?id=2519|||Try try the following:
declare @.dtcount datetime
declare @.days table
(
[Date] datetime
, [Day] int
)
set @.dtcount = '06/01/2005'
while @.dtcount <= getdate()
begin
if datepart(dw,@.dtcount) = 2
begin
insert into @.days
values (@.dtcount, datepart(dw,@.dtcount))
end
set @.dtcount = @.dtcount+1
end
select * from @.days
"Arul" wrote:

> I'm trying to find the number of Mondays since 6/1/2005. Any suggestions?
> THanks|||Arul wrote:
> I'm trying to find the number of Mondays since 6/1/2005. Any
> suggestions?
> THanks
Try this:
declare @.start datetime, @.today datetime, @.mondays int
set @.start='20050601'
set @.today= getdate()
set @.mondays= datediff(ww,@.start,@.today)
if datepart(dw,@.start)<3 set @.mondays=@.mondays+1
if datepart(dw,@.today) = 1 set @.mondays=@.mondays-1
select @.mondays
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.