Posted By

pats on 08/26/09


Tagged

date DateTime


Versions (?)

calculate quarters range between specific dates


 / Published in: Python
 

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

Report this snippet  

You need to login to post a comment.