I bumped into error message in subject. I extracted the code into bare minimum and I have to admit I'm completely puzzled on what is going on here. Python code looks like this:
from datetime import datetime
time_string = '2022-08-23 08:48:02'
time_time = datetime.strptime(time_string, '%Y-%m-%d %H:%M:%S')
print(type(time_time)) # outputs <class 'datetime.datetime'>
time_string_again= datetime.strftime("%Y-%m-%d",time_time) # throws error in question subject
print(time_string_again)
Could you please explain to me what is wrong with above code?
CodePudding user response:
You are using strftime in the wrong way. You can check the right usage here: https://www.programiz.com/python-programming/datetime/strftime
basically, strftime is applied to your datetime object:
time_string_again = time_time.strftime("%Y-%m-%d")