Problems with calculating timedelta in "% A,% B% d,% Y"

I want to use the following code snippet to turn the generator of upcoming days into readable words that I will store in a list using .strftime ("% A,% B% d,% Y").

base = datetime.today()
date_list = [base - timedelta(days=x) for x in range(0, 7)]
datescroll_list = ()

      

However, what is returned is in unreadable format. The methods I know to turn this format into a readable format don't work.

+3


source to share


1 answer


The code works fine if you add parsers, then call strftime:

from datetime import datetime,timedelta
base = datetime.today()
date_list = [(base - timedelta(days=x)).strftime(" %A, %B %d, %Y") for x in range(0, 7)]
print(date_list)

      



Output:

[' Saturday, June 20, 2015', ' Friday, June 19, 2015', ' Thursday, June 18, 2015', ' Wednesday, June 17, 2015', ' Tuesday, June 16, 2015', ' Monday, June 15, 2015', ' Sunday, June 14, 2015']

      

+4


source







All Articles