A memorandum because I wanted a date for one week from today due to weekly batch execution.
weekly_dates.py
from datetime import datetime, timedelta
#Output one by one
for i in xrange(7):
print (datetime.now()+timedelta(i)).strftime("%Y/%m/%d")
#Plunge into a list with list comprehension
print [(datetime.now()+timedelta(i)).strftime("%Y/%m/%d") for i in xrange(7)]
The execution result is like this.
$ python weekly_dates.py
2015/05/01
2015/05/02
2015/05/03
2015/05/04
2015/05/05
2015/05/06
2015/05/07
['2015/05/01', '2015/05/02', '2015/05/03', '2015/05/04', '2015/05/05', '2015/05/06', '2015/05/07']
Recommended Posts