1

I am trying to convert the date into week number of year.

In my case, I cannot include the day of one year into another year.

The isocalendar() works fine to find week number, however, it assumes some rules: if the first week in January has less than 4 days, it is counted as the last week of the year before.

So, this function returns:

date(2016, 1, 1).isocalendar()[1]
53

Is there some way, using this function, to change this, to return week 0 instead of week 53 (from previous year) ?

Cesar
  • 575
  • 3
  • 16

1 Answers1

2

how about this?

import datetime
datetime.date(2016, 1, 1).strftime("%U")
Nithin
  • 1,065
  • 8
  • 15