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?

ThatComputerGuy
  • 323
  • 3
  • 6
  • 11
  • Look at [`datetime.strftime()`](https://docs.python.org/3/library/datetime.html?highlight=strftime#datetime.datetime.strftime), e.g. `[d.strftime('%Y%m%d') for d in mondays]` – AChampion Feb 05 '19 at 05:02

1 Answers1

13

the following will work

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

Output

['20190214', '20190221']
Jeril
  • 7,858
  • 3
  • 52
  • 69