dynobase-icon
Dynobase

DynamoDB: Query Date Range (Guide w/ Code Examples)

Rafal Wilinski

Provided by Rafal Wilinski

To query a date range using the AWS JavaScript SDK, you can use the query operation.

var AWS = require('aws-sdk'); var dynamo = new AWS.DynamoDB({region: 'us-west-2'}); var params = { TableName: 'my-table', KeyConditionExpression: '#timestamp between :start_date and :end_date', ExpressionAttributeNames: { '#timestamp': 'timestamp' }, ExpressionAttributeValues: { ':start_date': {N: '1577836800'}, // January 1, 2020 ':end_date': {N: '1609459200'} // December 31, 2020 } }; dynamo.query(params, function(err, data) { if (err) { console.error(err); } else { console.log(data); } });

In this example, the KeyConditionExpression is set to check if the timestamp attribute is between :start_date and :end_date. The ExpressionAttributeNames and ExpressionAttributeValues are used to map the attribute names and values used in the expression to the actual attribute names and values in the table.

Tired of switching accounts and regions? Use Dynobase.

Try 7-day free trial. No strings attached.

Product Features

Download
/
Changelog
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2024 Dynobase
+
Better DynamoDB Experience.
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.