mandeepsinghn
mandeepsinghn

Reputation: 94

Date time base filter in dynamodb with node js

I am working on a DynamoDB project with node js and I want to fetch some data between two dates. So what i can do for date base filter please provide any code sample in nodejs for this problem. You can assume that we have to fetch student admission between two dates.

Upvotes: 0

Views: 4157

Answers (1)

notionquest
notionquest

Reputation: 39186

You can use BETWEEN to filter the items between two dates.

BETWEEN : Greater than or equal to the first value, and less than or equal to the second value.

Example params of Query API:-

var params = {
    TableName : table,
    KeyConditionExpression : 'yearkey = :hkey and title = :rkey',
    FilterExpression : 'createdate between :val1 and :val2',
    ExpressionAttributeValues : {
        ':hkey' : year_val,
        ':rkey' : title,
        ":val1" : "2010-12-21T16:42:31",
        ":val2" : "2010-12-21T17:42:35"
    }
};

Database Item:-

GetItem succeeded: {
  "Items": [
    {
      "createdate": "2010-12-21T17:42:34Z",
      "title": "The Big New Movie 2010",
      "yearkey": 2010,
      "info": {
        "rating": 0,
        "plot": "Nothing happens at all."
      }
    }
  ],
  "Count": 1,
  "ScannedCount": 1
}

Upvotes: 3

Related Questions