Connecting Tech Pros Worldwide Forums | Help | Site Map

Get weeknumbers from a given date in ASP.

MONO
Guest
 
Posts: n/a
#1: Jul 19 '05
Hello!

I´m trying to get the weeknumber fom a given date but at some dates
will return the wrong weeknumber.

WeekNumber = DatePart("ww", TodayAsDate, vbMonday, vbFirstFourDays)

like 2003-12-27

I know that this is a Microsoft bug but i have tried their soultion
http://support.microsoft.com:80/supp.../q200/2/99.asp

but still it will return strange weeknumbers at some dates.


I want the output in weeks from 1 - 52 and every week starts with a
Monday.

Does anyone have a good function to output the weeknumbers from
a given date?


Micke
Bob Barrows
Guest
 
Posts: n/a
#2: Jul 19 '05

re: Get weeknumbers from a given date in ASP.


You cannot avoid having some dates return 53 as the week number. Think about
it. Using your definition, any year where 1-Jan is a Monday will have 53
weeks . What week number should 12/31/2001 return?

Try this script so you see the problem:
<%
dim d, i
d=#1/1/2001#
do until weekday(d) = vbMonday
d=dateadd("d",1,d)
loop
i=1
do until d > #1/1/2002#
Response.Write d & ": " & i & "<BR>"
d=dateadd("ww",1,d)
i = i + 1
loop
%>

Bob Barrows

MONO wrote:[color=blue]
> Hello!
>
> I´m trying to get the weeknumber fom a given date but at some dates
> will return the wrong weeknumber.
>
> WeekNumber = DatePart("ww", TodayAsDate, vbMonday, vbFirstFourDays)
>
> like 2003-12-27
>
> I know that this is a Microsoft bug but i have tried their soultion
> http://support.microsoft.com:80/supp.../q200/2/99.asp
>
> but still it will return strange weeknumbers at some dates.
>
>
> I want the output in weeks from 1 - 52 and every week starts with a
> Monday.
>
> Does anyone have a good function to output the weeknumbers from
> a given date?
>
>
> Micke[/color]


MONO
Guest
 
Posts: n/a
#3: Jul 19 '05

re: Get weeknumbers from a given date in ASP.


Ohoooo, I´ve got major meltdown in my brain. I don´t know what i was
thinking about. Everthing is working fine.

Thanks for helping me think :-)
/mike


"Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message news:<uI2yKUajDHA.976@tk2msftngp13.phx.gbl>...[color=blue]
> You cannot avoid having some dates return 53 as the week number. Think about
> it. Using your definition, any year where 1-Jan is a Monday will have 53
> weeks . What week number should 12/31/2001 return?
>
> Try this script so you see the problem:
> <%
> dim d, i
> d=#1/1/2001#
> do until weekday(d) = vbMonday
> d=dateadd("d",1,d)
> loop
> i=1
> do until d > #1/1/2002#
> Response.Write d & ": " & i & "<BR>"
> d=dateadd("ww",1,d)
> i = i + 1
> loop
> %>
>
> Bob Barrows
>
> MONO wrote:[color=green]
> > Hello!
> >
> > I´m trying to get the weeknumber fom a given date but at some dates
> > will return the wrong weeknumber.
> >
> > WeekNumber = DatePart("ww", TodayAsDate, vbMonday, vbFirstFourDays)
> >
> > like 2003-12-27
> >
> > I know that this is a Microsoft bug but i have tried their soultion
> > http://support.microsoft.com:80/supp.../q200/2/99.asp
> >
> > but still it will return strange weeknumbers at some dates.
> >
> >
> > I want the output in weeks from 1 - 52 and every week starts with a
> > Monday.
> >
> > Does anyone have a good function to output the weeknumbers from
> > a given date?
> >
> >
> > Micke[/color][/color]
Closed Thread