dongxie3963 2017-07-25 13:24
浏览 74
已采纳

使用PHP扫描DynamoDB表以获取当月的结果

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?

  • 写回答

1条回答 默认 最新

  • dragon5006 2017-07-25 16:37
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM