I have a date with format in 'yyyy-dd-mm'. How do I convert to 'yyyy-mm-dd' format, been bit of a struggle with strftime and strptime!
Assuming the date is '1919-01-12', I want to see it in the format '1919-12-01'.
I have a date with format in 'yyyy-dd-mm'. How do I convert to 'yyyy-mm-dd' format, been bit of a struggle with strftime and strptime!
Assuming the date is '1919-01-12', I want to see it in the format '1919-12-01'.
from datetime import datetime
date = '1919-01-12'
formatted_date = datetime.strptime(date, '%Y-%d-%m').strftime('%Y-%m-%d')
datetime.strptime(date, '%Y-%d-%m')
creates a datetime object from a string, .strftime('%Y-%m-%d')
formats the datetime as a string accoring to the specified pattern
try this code
import datetime
print (datetime.datetime.strptime("1919-01-12", "%Y-%d-%m").strftime("%Y-%m-%d"))