0

I am converting the following string 2020-02-14 20:56:00 to datetime.date format. But am getting the following error:

ValueError: time data '2020-02-14 20:56:00' does not match format '%Y/%m/%d %H:%M:%S'

Here is the code I am using:

from datetime import datetime 
date_and_time = '2020-02-14 20:56:00'
date_and_time = datetime.strptime(date_and_time, '%Y/%m/%d %H:%M:%S')

What am I doing wrong here?

1
  • 2
    Replace '/' with '-' Commented Feb 16, 2020 at 5:45

1 Answer 1

1

The ValueError specifies the use of incorrect format string.
To resolve this error you have to replace / with -.
Here is correct code:

from datetime import datetime 
date_and_time = '2020-02-14 20:56:00'
date_and_time = datetime.strptime(date_and_time, '%Y-%m-%d %H:%M:%S')

Hope it helps you:)

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.