Programming Languages

Week number in Python

In Python date and datetime objects own a method called isocalendar() which returns a list containing three ISO 8601 values: the ISO year, the ISO week number and the ISO weekday.


Get the current week number and print it.

from datetime import date

weekNumber = date.today().isocalendar()[1]
print 'Week number:', weekNumber


Week number:38
comments powered by Disqus