5
votes

I have a dynamodb table which has a GlobalSecondaryIndex with a date field as attribute of keytype "range". Values are stored in ISO-format "YYYY-MM-DD". I want to access in node only records with dates greater than a certain date. It seems to work with a parameter for my query:

KeyConditionExpression: 'myDate >= :myDate',
ExpressionAttributeValues: {   
    ':myDate': '2017-11-17'
}

However I do not quite understand. The date is technically speaking a string. Is it reliable to trust the string comparison or should it be done in a different way?

1

1 Answers

3
votes

Yes, you can relay on this as long as the date is stored in YYYY-MM-DD format.

DynamoDB doesn't have a separate data type for Date. Date can be stored either as String or Number.

Date    S (string type). The Date values are stored as ISO-8601 formatted strings.

Storing date as String:-

You can use the string data type to represent a date or a time stamp. One way to do this is by using ISO 8601 strings, as shown in these examples:

  • 2016-02-15

  • 2015-12-21T17:42:34Z

  • 20150311T122706Z

Storing date as Number:-

You can use the number data type to represent a date or a time stamp. One way to do this is by using epoch timeā€”the number of seconds since 00:00:00 UTC on 1 January 1970. For example, the epoch time 1437136300 represents 12:31:40 UTC on 17 July 2015.

Data types