weekday diff

Microsoft SQL Server

Hi All,

Is there anyway I can find the differenct between a day "d1" and day
"d2" in the terms of weekday?
For example is d1 is Monday and d2 is the first Monday after d1, the
datedifference between them in terms of weekdays is 5. Similarly is
there a function which computes the number of weekends between d1 and
d2?
Hi

Do you actually need weekday or do you require working day? For either case
probably the easiest solution is to have a calendar table as described in
http://tinyurl.com/ydwqyr and similar posts. Also see
http://www.aspfaq.com/2519 on calendar tables.

John
Thanks. Is there easier solution if I only wants all weekdays?
Just weekdays?

select top 100000 identity(int, 0, 1) Nbr into #Seq
from master..sysobjects cross join master..sysobjects
sysjoin
alter table #Seq add constraint PK_Seq primary key (Nbr)
go
create table Calendar (
CalDate smalldatetime primary key,
IsWeekEnd bit default 0
)
-- Populate the calendar table
set datefirst 1
declare @Date datetime
select @Date = '20060101'
insert Calendar
select @Date + Nbr,
0 end
from #Seq
where Nbr <= datediff(dd, @Date, '20790606')

declare @FromDate datetime
declare @ThruDate datetime
select @FromDate = '20060308', @ThruDate = '20060310'

select datename(dw,CalDate) from Calendar
where CalDate between @FromDate and @ThruDate
and IsWeekEnd = 0