7

I have a list of Dates returning Mondays between two dates

mondays =[datetime.date(2019, 2, 14), datetime.date(2019, 2, 21)]

How do I format this list to %Y%m%d format?

Expecting output list to be in the below format:

['20190214','20190221']

is there a way?

1
  • Look at datetime.strftime(), e.g. [d.strftime('%Y%m%d') for d in mondays] Commented Feb 5, 2019 at 5:02

1 Answer 1

14

the following will work

[date_obj.strftime('%Y%m%d') for date_obj in mondays]

Output

['20190214', '20190221']
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.