I'm trying to convert the existing dates from March 02, 2019 6:30 - 11:00 pm
to 3/2/19
format but I can't get any idea as to how I can do it.
These are the dates:
datelist = [
"March 02, 2019 6:30 - 11:00 pm",
"June 21, 2019",
"March 22, 2019 5:00 - 10:00 pm",
"May 01, 2019 - June 15, 2019 11:59 pm",
"May 02, 2019 5:30 - 8:00 pm",
"May 04, 2019 5:00 - 10:30 pm",
"September 08, 2018 6:00 - 10:00 pm",
]
for date in datelist:
print(date)
Expected output:
3/2/2019
6/21/2019
3/22/2019
5/1/2019 - 6/15/2019
5/2/2019
5/4/2019
9/8/2018
This is the closest that I could find out:
import datetime
date_time_str = 'Jun 28 2018 7:40AM'
date_time_obj = datetime.datetime.strptime(date_time_str, '%b %d %Y %I:%M%p').strftime('%m/%d/%Y')
print(date_time_obj)
But, that doesn't actually serve the purpose when I have different type of dates in the list.
How can I convert dates to the desired format?