Reputation: 6555
I need to change the date into the format MM/YY
. The issue is I don't always don't what the date format is to begin with. It's my understanding that the code below would need to know what format the date was in first before I can change it is that correct?
newdate = datetime.datetime.strptime(str(mydate), '%Y/%m/%d').strftime('%m-%Y')
as a result I get the error:
time data '2020-09-30' does not match format '%Y/%m/%d' (
How to I convert my date to MM/YY?
I'm using Django 1.4.6
Upvotes: 0
Views: 858
Reputation: 76
newdate = datetime.datetime.strptime(str(mydate), '%Y-%m-%d').strftime('%m/%Y')
Upvotes: 4