[egenix-users] week of year

M.-A. Lemburg mal at lemburg.com
Mon May 27 12:28:50 CEST 2002

Dirk Holtwick wrote:
> Hi,
> I noticed some strange behaviour with values for "week of year" with 
> mx.DateTime. I use something like this in my program:
>     Date(year, month, w).strftime("%W")
> e.g.: Date(2002,5,1).strftime("%W") gives 17 as result. In my german 
> calendar it should be 18, so I add 1. But
> Date(2001,5,1).strftime("%W") gives 18 and in my calendar its also 18 so 
> adding +1 dosn't work here. what can I do? I use Date(2001,5,1).iso_week[1]
> and Date(2002,5,1).iso_week[1] that works. But shouldn't it also work 
> with the method described above?

The .strftime() method interfaces directly to the C lib's
strftime() API, so if that implementation uses a non-ISO
week number calculation, then you see different results.

        %W     The week number of the current year as a decimal number,  range
               00  to  53,  starting with the first Monday as the first day of
               week 01.

This is clearly not ISO (which is much more complicated) !

Marc-Andre Lemburg
CEO eGenix.com Software GmbH
Company & Consulting:                           http://www.egenix.com/
Python Software:                   http://www.egenix.com/files/python/

More information about the egenix-users mailing list