Dynamodb has timestamp attribute which stores date and time "Thu Jan 14 19:55:27 UTC 2021" in String format. Now, I want to retrieve records which are in between "Thu Jan 11 20:55:27 UTC 2021" and "Thu Jan 13 22:15:27 UTC 2021". Below is the code:
from datetime import datetime
from boto3.dynamodb.conditions import Attr
def lambda_handler(event, context):
startdatetime=event["startdate"]
enddatetime=event["enddate"]
start=datetime.strptime(startdatetime,"%a %b %d %H:%M:%S UTC %Y")
end=datetime.strptime(enddatetime,"%a %b %d %H:%M:%S UTC %Y")
fe=Attr('timestamp').between(start,end)
response = table.scan(
FilterExpression=fe
)
This is not giving proper set of records as comparision is happening between string and datetime. Converting Attr() to datetime is not happening. Below is the code snippet I tried:
fe=datetime.strptime(str(Attr('timestamp')),"%a %b %d %H:%M:%S UTC %Y").between(start, end)
This also didnt help.
Any suggestions on this ?