0

I have used sqlalchemy to retrive data from my database and store it within an object. I now need to find the first line where a datetime ('created_at') value is greater than another that I provide. The data is in this format.

{id: 1, 'user': 1, 'setpoints' : [{setpoint1, setpoint2}], 'data':[{'created_at': '2022-06-10 12:00:00', 'data': {data1, data2}]}

I have tried using this question, and I have made a mistake somewhere, but I do not understand the answer enough to adapt it for my situation.

I wrote this:

startPos = next((i for i, v in enumerate(hardware['data']) if datetime.strptime(v['created_at'],'%Y-%m-%dT%H:%M:%S') > startTime), None)

Could anybody please explain where I am going wrong?

The Candy King
  • 89
  • 1
  • 1
  • 10

1 Answers1

1

your datetime format in created_at is not in a correct isoformat.

your data is 2022-06-10 12:00:00 but the isoformat itself is %Y-%m-%dT%H:%M:%S.

You already write it right at the format above but wrong in the data you have.

So it should be 2022-06-10T12:00:00

danangjoyoo
  • 350
  • 1
  • 6