How to get week number in Python?


Question

How to find out what week number is current year on June 16th (wk24) with Python?

1
288
12/13/2017 7:05:52 AM

datetime.date has a isocalendar() method, which returns a tuple containing the calendar week:

>>> import datetime
>>> datetime.date(2010, 6, 16).isocalendar()[1]
24

datetime.date.isocalendar() is an instance-method returning a tuple containing year, weeknumber and weekday in respective order for the given date instance.

351
9/17/2018 9:43:31 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon