week-number.net

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.

Example

Get the current week number and print it.


from datetime import date

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

Output:

Week number:3
comments powered by Disqus