Weeknumbers

  • Thread starter Thread starter bpsdgnews
  • Start date Start date
B

bpsdgnews

Hi,

This:

DatePart(DateInterval.WeekOfYear, DateSerial(2008,12,29),
FirstDayOfWeek.Monday, FirstWeekOfYear.FirstFourDays)

Returns 53.

DatePart(DateInterval.WeekOfYear, DateSerial(2001,1,1),
FirstDayOfWeek.Monday, FirstWeekOfYear.FirstFourDays)

Returns 1.

Both days were in the same week. Our weeks start at monday. So there
were four days of january in this week. So in my opinion both should
have returned 1.

Any suggestions on how I can get the proper weeknumber?
 
Hi,

This:

DatePart(DateInterval.WeekOfYear, DateSerial(2008,12,29),
FirstDayOfWeek.Monday, FirstWeekOfYear.FirstFourDays)

Returns 53.

DatePart(DateInterval.WeekOfYear, DateSerial(2001,1,1),
FirstDayOfWeek.Monday, FirstWeekOfYear.FirstFourDays)

Returns 1.

Both days were in the same week. Our weeks start at monday. So there
were four days of january in this week. So in my opinion both should
have returned 1.

Any suggestions on how I can get the proper weeknumber?

Huh? Why would you expect a day in December return anything less than
48? It is the 53rd week of 2008, not the 1st week of 2009.
 
Hello bpsdg
Hm, the problem is that returning "1" for 29/12/2008 would be ambiguous.
So making it a 53 keeps things on the safe side. On the other hand,
1/1/2006 is week 52...

According to http://en.wikipedia.org/wiki/ISO_week it should have
reported "1" (since 1/1/2009 is a Thursday). Either .NET does not
follow ISO or it is a bug.

Best regards,

Martin

Am 30.12.2009 21:47, schrieb bpsdgnews:
 
Hello bpsdg
Hm, the problem is that returning "1" for 29/12/2008 would be ambiguous.
So making it a 53 keeps things on the safe side. On the other hand,
1/1/2006 is week 52...

According to http://en.wikipedia.org/wiki/ISO_week it should have
reported "1" (since 1/1/2009 is a Thursday). Either .NET does not
follow ISO or it is a bug.

Best regards,

Martin

The docs (MSDN) do not say they follow the ISO definition.
 
THanks for all the suggestions and information. I will look into it.

The strange thing to me is that VB6 did alright with this.

format(dateserial(2009,12,29),"ww",vbMonday,vbFirstFourDays)

Returned 53 in VB6.
 
bpsdgnews said:
THanks for all the suggestions and information. I will look into it.

The strange thing to me is that VB6 did alright with this.

format(dateserial(2009,12,29),"ww",vbMonday,vbFirstFourDays)

Returned 53 in VB6.

MsgBox( _
Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear( _
#12/29/2009#, Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday _
) _
)

Returns 53 in VB 2008.
 
MsgBox( _
   Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear( _
      #12/29/2009#, Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday _
   ) _
)

Returns 53 in VB 2008.

Thanks Armin,

But I gave the wrong example. Getting confused from all these
dates. ;-)

I ment to write:

VB6:

format(dateserial(2008,12,29),"ww",vbMonday,vbFirstFourDays)

Returns 1.


VB 2008:

Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear
(#12/29/2008#, Globalization.CalendarWeekRule.FirstFourDayWeek,
DayOfWeek.Monday)

Returns 53.


Regards, Bas.
 
Back
Top