How to generate a specific date range in the YearMonthDay format?

advertisements

Is there a way to generate a list of dates in the form YearMonthDay in Python? I need to make a list containing dates in that format for every Saturday between June 12 2010 and December 8 2012.

I tried pandas.date_range('6/12/2010','12/8/2012', freq='W-SAT') but I was unable to convert the resulting timestamp objects to the format mentioned above.


Since pandas 0.8 the Timestamp type subclasses the standard datetime class in the standard library. Consequently, you can use datetime.strftime,

>>> [ d.strftime('%Y%m%d') for d in pandas.date_range('6/12/2010','12/8/2012', freq='W-SAT') ]
['20100612',
 '20100619',
 '20100626',
 '20100703',
...