The 字符串数据类型应用于日期或时间戳。
您可以使用字符串数据类型来表示日期或时间戳。
实现此目的的一种方法是使用 ISO 8601 字符串,如下所示
例子:
2016-02-15
2015-12-21T17:42:34Z
20150311T122706Z
DynamoDB 日期或时间戳的数据类型 https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html#HowItWorks.DataTypes.String
是的,当日期存储为字符串时,支持范围查询。这BETWEEN可以用在 FilterExpression 上。我使用以下过滤表达式获取了结果中的项目。
没有时间的 FilterExpression:-
FilterExpression : 'createdate between :val1 and :val2',
ExpressionAttributeValues : {
':hkey' : year_val,
':rkey' : title,
":val1" : "2010-01-01",
":val2" : "2010-12-31"
}
FilterExpression with time:-
FilterExpression : 'createdate between :val1 and :val2',
ExpressionAttributeValues : {
':hkey' : year_val,
':rkey' : title,
":val1" : "2010-01-01T00:00:00",
":val2" : "2010-12-31T00:00:00"
}
数据库值:-
格式 1 - 带时区:
{"Item":{"createdate":{"S":"2010-12-21T17:42:34+00:00"},"title":{"S":"The Big New Movie 2010"},"yearkey":{"N":"2010"},"info":{"M":{"rating":{"N":"0"},"plot":{"S":"Nothing happens at all."}}}}}
格式 2 - 无时区:-
{"Item":{"createdate":{"S":"2010-12-21T17:42:34Z"},"title":{"S":"The Big New Movie 2010"},"yearkey":{"N":"2010"},"info":{"M":{"rating":{"N":"0"},"plot":{"S":"Nothing happens at all."}}}}}