0

Hi I am trying to convert this string in Python : '2019-01-10' into date format as 2019-01-10

I have tried this code :

from datetime import datetime

date_time_str = '2019-01-10'

date_time_obj = datetime.strptime(date_time_str, '%y-%m-%d )

but i have a ValueError : time data '2019-01-10' does not match format '%y-%m-%d'

Can you help me please ?

2 Answers 2

2

%y format specifier is 2 digits, use uppercase %Y. Ref: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes

Sign up to request clarification or add additional context in comments.

Comments

2
from datetime import datetime
date_time_str = '2018-06-29'
date_time_obj = datetime.strptime(date_time_str, '%Y-%m-%d')

try changing it to the above code.

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.