DynamoDB: Query Date Range (Guide w/ Code Examples)
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.
Similar Code Examples
- DynamoDB: Query Greater Than
- DynamoDB: Delete
- DynamoDB: Query Count
- DynamoDB Get in Typescript
- DynamoDB: Get Unique Values
- DynamoDB: Get List Of Items
- DynamoDB: Attribute Not Null
- DynamoDB: Get Random Item
- DynamoDB: Query Ends With
- DynamoDB: Delete All Items With Partition Key
- DynamoDB: Batch Get
- DynamoDB: Increment Counter
- DynamoDB: Query KeyConditionExpression
- DynamoDB: Query Global Secondary Index in Nodejs
- DynamoDB: Get Last Inserted Item
Login to the AWS Console less. Use Dynobase.
Try 7-day free trial. No credit card needed.
Product Features
DynamoDB Tools
DynamoDB Info
© 2024 Dynobase