0

I have a date as "1-Jun". How can I convert this to 01/06? I am using Strptime. I thought this is going to be easy but it is not.

Error that I am getting: time data '1-Jun' does not match format '%d-%Mmm'. This is the command I am using. Can anyone help me with this?

datetime.datetime.strptime(date, '%d-%Mmm').strftime('%m/%d')

1 Answer 1

2

There's no such format as %Mmm, what you need to match Jun is %b ("Locale's abbreviated month name"). Also, if you want 01/06 rather than 06/01 it is going to be '%d/%m' in strftime:

print(datetime.datetime.strptime('1-Jun', '%d-%b').strftime('%d/%m'))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.