GrantU
GrantU

Reputation: 6555

Django date format issue - does not match format

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

Answers (1)

Ning
Ning

Reputation: 76

newdate = datetime.datetime.strptime(str(mydate), '%Y-%m-%d').strftime('%m/%Y')

Upvotes: 4

Related Questions