Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wrong week number in 2013

Tags:

python

i'm using my backup script since 2011 and had no problems at all. But since start of 2013 I'm getting problem with the correct week number.

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.strftime("%W", time.localtime())
'02'

But we have week number 3

Am i doing something wrong? It was working till 2013.

Thanks.

like image 674
user1976568 Avatar asked Jan 15 '23 12:01

user1976568


1 Answers

"""Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0."""

What you are looking for is the value for the week number as defined through the ISO standard.

Look at the isoweek module.

>>> from isoweek import Week
>>> Week.thisweek()
isoweek.Week(2013, 3)
>>> Week.thisweek().week
3
like image 51
Andreas Jung Avatar answered Jan 17 '23 05:01

Andreas Jung