List: General Discussion « Previous MessageNext Message » From: Michael Widenius Date: April 27 1999 8:09am Subject: Re: Week in year before 1998 starts from 1 instead of 0 View as plain text
```>>>>> "Aldrian" == Aldrian Gintingsuka <aldrian@stripped>
> writes:

Aldrian> I might be a little unclear about my problem. What I am confused about is why
Aldrian> the WEEK command returns 0 for Jan 1 of some years and returns 1 for some
Aldrian> other years.

Aldrian> WEEK('1997-01-01') => 1;
Aldrian> WEEK('1998-01-01') => 0;

Aldrian> I received a direct response from Piet Wesselman, and (with his his
Aldrian> permission) would like to share it here in the list.

>> On Mon, 26 Apr 1999, Piet Wesselman wrote:
>>
pwessel> January 1 is only in week 1, if this week contains the first Thursday
pwessel> of the year (or January 4, which is the same). See the ISO 8601:1988
pwessel> Maybe this helps.
pwessel>
pwessel> Piet Wesselman
pwessel>

Aldrian> And after testing some other years, I think I begin to understand how it
Aldrian> works.

Aldrian>   Jan 1 is in week 1 if that week contains at least four days (more than the
Aldrian>   number of days in the previous year's last week).

Aldrian>     If Sunday is the 1st day of the week,
Aldrian>     Jan 1 is in week 1 if it starts in (Sun, Mon, Tue, Wed)

Aldrian>     If Monday is the 1st day of the week,
Aldrian>     Jan 1 is in week 1 if it starts in (Mon, Tue, Wed, Thu)

Aldrian>     Otherwise, it is in week 0 (continuation of the last week of the previous
Aldrian>     year).

Aldrian> Is that how weeks are calculated in MySQL???

Yes; When WEEK() returns a number in the range 1-52, it will always be
identical to the week number on your calendar.  The week 0 is the last
week of the previous year.  53 is the first week of next year.

Regards,
Monty
```
Week in year before 1998 starts from 1 instead of 0aldrian23 Apr
• Week in year before 1998 starts from 1 instead of 0Michael Widenius26 Apr
• Re: Week in year before 1998 starts from 1 instead of 0Aldrian Gintingsuka26 Apr
• Re: Week in year before 1998 starts from 1 instead of 0Michael Widenius27 Apr
• Re: Week in year before 1998 starts from 1 instead of 0Aldrian Gintingsuka27 Apr
• Re: Week in year before 1998 starts from 1 instead of 0Michael Widenius27 Apr