calculate quarters range between specific dates - correct version


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. def quarters_range(date_to, date_from=None):
  2. result = []
  3. if date_from is None:
  4. date_from = datetime.now()
  5. quarter_from = (date_from.month/4)+1
  6. quarter_to = (date_to.month/4)+1
  7. for year in range(date_from.year, date_to.year+1):
  8. for quarter in range(1, 5):
  9. if date_to.year == year and quarter >= quarter_to:
  10. break
  11. if date_from.year == year and quarter <= quarter_from:
  12. continue
  13. result.append([quarter, year])
  14. return result

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.