get lastweek dates using python? get lastweek dates using python? python-3.x python-3.x

get lastweek dates using python?


Your question and algorithm don't seem to correspond. Is this what you're after?

from datetime import datefrom datetime import timedeltatoday = date(2014, 10, 10) # or you can do today = date.today() for today's datefor i in range(0,7):    print (today - timedelta(days=i))


@MarkG hit the nail on the head but if you're looking to get the exact output as asked this would work:

import datetimetoday = '10 OCT 2014'dates = [datetime.datetime.strptime(today, '%d %b %Y') - datetime.timedelta(days=i) for i in range(7)]print ', '.join([day.strftime('%d %b %Y').upper() for day in dates])

Note that you need to pass the today's date as a string.