Weeknumber is off

  • Thread starter Thread starter Harmannus
  • Start date Start date
H

Harmannus

Hallo,

I use the below code to generate a weeknumber

Week: Format(DatePart("ww";[Mydate]);"00")

If Mydate is 10 january Access says its week 3. This is probebly due to the
fact that last yeas was a year with 53 weeks. The first of january started
in week 53...

Any suggestions on how to correct this?

Thanx for any tips!

Regards,
Harmannus
 
it's due to the default settings of the DatePart() function: the default
value for the third argument FirstDayOfWeek is Sunday, and the default value
for the fourth argument FirstWeekOfYear is Jan1. this means that the week in
which Jan 1 falls is week one, even when Jan 1 falls on the last day of the
week, as it did this year.

you can change the FirstDayOfWeek setting to Saturday, as

DatePart("ww", [Mydate], 7)

or, you can change the FirstDayOfYear setting to FirstFullWeek, as

DatePart("ww", [Mydate], , 3)

suggest you read up on the DatePart Function topic in Help, for an in-depth
explanation.

hth
 
Back
Top