Reputation: 5
I have a date format of mm/dd/yyyy
I need to convert into yyyy/mm/dd
published_date = self.clean(published_dateformat).split('at')[0]
new_published_date = datetime.date.strftime(published_date,"%Y/%m/%d")
Upvotes: 0
Views: 295
Reputation: 178
you can do this like this.
from datetime import datetime
published_dateformat = "7/11/2019 at 7.09pm"
published_date = (published_dateformat).split('at')[0][:-1]
print(datetime.strptime(published_date,'%d/%m/%Y').strftime("%Y/%m/%d"))
Upvotes: 1
Reputation: 818
try this:
from datetime import datetime
published_dateformat = "7/11/2019 at 7.09pm"
published_date = published_date = (published_dateformat).split('at')[0][:-1]
published_date = datetime.strptime(published_date,"%d/%m/%Y")
new_published_date = published_date.strftime("%Y/%m/%d")
With this, new_published_date
will have value of '2019/11/07'
Upvotes: 0