I have a table in AWS DynamoDB, and every item in this table has a String-type "date" attribute, which contains the date when the specific item was created. The date in this attribute is being saved in this format: dd/mm/YYYY
.
What I want to do is to scan this table, and get all of the results from the current month. I also want to do 2 more individual scans. One for results from the last month (for example, now it is July, so I want to get results from June), and from 2 months ago (for example, I want to get all the results from May).
In the DynamoDB PHP SDK documentation, they are demonstrating a scan, and in the example they are filtering the scan according to an attribute called "time" using this code:
'time' => array(
'AttributeValueList' => array(
array('N' => strtotime('-15 minutes'))
),
'ComparisonOperator' => 'GT'
)
So I thought that I could replace -15 minutes
with -1 month
, but the problem with it is that, as you can see in the code above, the "time" attribute is a Number-type, and not String-type, so I can't perform this action.
What can I do to get results only from the current month?
If you store data in yyyy/mm/dd
format you can use begin_with
function to filter your data:
begins_with ( sortKeyName, :sortkeyval ) - true if the sort key value begins with a particular operand. (You cannot use this function with a sort key that is of type Number.) Note that the function name begins_with is case-sensitive.
Otherwise I don't see how it is possible on data of this format.
Another option is to convert it into Unix timestamps and then you can use <,<=,>,>= or between
operators