Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a list of DateTime objects to string in python [duplicate]

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?

like image 520
ThatComputerGuy Avatar asked Jul 19 '26 00:07

ThatComputerGuy


1 Answers

the following will work

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

Output

['20190214', '20190221']
like image 141
Jeril Avatar answered Jul 21 '26 13:07

Jeril



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!