简体   繁体   中英

comparen today's date with date format YYYY-DD-MM in dynamodb table

I have a table of name: DATETABLE with date values YYYY-DD-MM and data type is String in AWS dynamodb it has partition key has date which is String

const currentdate = new Date().toISOString().split('T')[0];
client.query({
  TableName: 'date',
  KeyConditionExpression: 'date = :todaydate',
  ExpressionAttributeValues: {
    ':todaydate': currentdate
  }
})

I only to want to compare date values with current(today's) date like using key condition which will be

 KeyConditionExpression: 'date = :currentdate',

return true or false based on input. which will be like direct query SELECT * FROM date WHERE DATE = 2022-14-12(current date) (table value)

Error: UnexpectedParameter: Unexpected key '7' found in params.ExpressionAttributeValues[':date']

Try:

const currentdate = new Date().toISOString().split('T')[0];
client.query({
  TableName: 'date',
  KeyConditionExpression: 'date = :todaydate',
  ExpressionAttributeValues: {
    ':todaydate': {'S':currentdate}
  }
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM