Reputation: 9492
I am trying to generate the number of the week based on the date that user input. I am aware of this following function that will give me the specific week number for the date that i input.
datetime.date(2012,5,21).isocalendar()[1]
my problem is that i want to make the week 1 of my year to start in April 1st instead of Jan 1st. Which means, my calendar for every year starts from April 1 and ends at march 31. Not Jan 1 to dec 31. Is there any build in function i can use?
Upvotes: 2
Views: 448
Reputation: 5683
Use datetime
from datetime import date
end = date(2012, 5, 21)
start = date(2012, 4, 1)
Diff = end - start
print Diff.days / 7 # convert to number of weeks
Upvotes: 2