0

I have a date time value November 10, 2021 which is to be converted into Django default datetime. I tried but got this error.

I have a date value which I got from list of dictionaries like this which is a datetime field.

created_at = data[0]['created_at']
print(created_at)

The print I got is like June 12, 2021

Now I tried this.

c = created_at.strftime(('%Y-%m-%d %H:%M:%S'))
print(created_at)
print(c)

When I print c, I got the above error. I know created_at object doesnt have strftime function but how can this conversion be done??

Reactoo
  • 916
  • 2
  • 12
  • 40
  • 1
    The date you're getting from your dictionary is a string. That string can't be used as an object. Convert that string in to a datetime object then you can apply `strftime` to it. – Cl0ud-l3ss Nov 10 '21 at 10:52
  • 2
    https://stackoverflow.com/questions/466345/converting-string-into-datetime This should help. Pass your string through strptime; then format however you wish. Or format it whilst parsing. – Cl0ud-l3ss Nov 10 '21 at 10:53

0 Answers0