How to list next 24 months' start dates with python? -


please tell me how can list next 24 months' start dates python,

such as:

01may2014 01june2014 . . . 01aug2015 

and on

i tried:

import datetime  this_month_start = datetime.datetime.now().replace(day=1)  in xrange(24):     print  (this_month_start + i*datetime.timedelta(40)).replace(day=1) 

but skips months.

just increment month value; used datetime.date() types here that's more enough:

current = datetime.date.today().replace(day=1)  in xrange(24):     new_month = current.month % 12 + 1     new_year = current.year + current.month // 12     current = current.replace(month=new_month, year=new_year)     print current 

the new month calculation picks next month based on last calculated month, , year incremented every time previous month reached december.

by manipulating current object, simplify calculations; can i offset well, calculation gets little more complicated.

it'll work datetime.datetime() too.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -