Search code examples
python-3.xdatetimeamazon-dynamodbcloud

What would be the most efficient way to compare string datetime values?


I have a dynamoDB that has two string time objects. One is when the item was created and the other is when it was updated(processed). I am checking if the item was updated within 2 days of creation using the following conversions and then just using an if statement to compare if updateTime is greater than creationTime. But is this the best way to go about this?

creationTime = datetime.datetime.strptime(acc.createdAt,'%H:%M')
modcreationTime = creationTime + datetime.timedelta(days=2)
updateTime = datetime.datetime.strptime(acc.updatedAt,'%H:%M')

Solution

  • Creating the Metrics in CloudWatch using the data turned out to be the best solution. It simplified the code to a great extent and made the data easy to work with.