【问题标题】:One year back query datetime一年前的查询日期时间
【发布时间】:2013-10-30 02:51:09
【问题描述】:

我想获取一年前从现在开始的所有记录,但它无法正常工作。 在 CodeIgniter 中制作

这是我的问题,有什么问题吗? :

    $currentDate = date("Y-m-d H:m:s");
    $yeardate=date('Y-m-d H:m:s', strtotime('-1 year'));
    $this->db->select('TimeStamp');
    $this->db->where('Transaction', 'COMPLETED');
    $this->db->where('TimeStamp>=',$yeardate);
    $this->db->where('TimeStamp<=',$currentDate);
    $query = $this->db->get('R_Logs');
    $results = $query->result();

提前致谢

【问题讨论】:

  • 定义not working exactly.

标签: php mysql codeigniter


【解决方案1】:

我忘记在 TimeStamp = 之间添加一个空格。 我的错。

【讨论】:

    【解决方案2】:

    我认为尝试 Epoch 时间然后从中查询可能更容易 - 例如Get epoch for a specific date using Javascript

    这会将日期转换为自 1970 年 1 月 1 日以来的天数。然后您可以从中减去 365 天(或使用 yearInteger %4 技巧来确定它是否是闰年)

    【讨论】:

      【解决方案3】:

      尝试更改这两行:

      $currentDate    = date("Y-m-d H:i:s");
      $yeardate       = strtotime(date('Y-m-d H:i:s') . ' -1 year');
      

      转储您的查询并调试:

      echo $this->db->last_query();
      

      【讨论】:

        猜你喜欢
        • 2022-01-17
        • 1970-01-01
        • 2011-12-29
        • 2011-11-11
        • 1970-01-01
        • 2014-11-22
        • 1970-01-01
        • 1970-01-01
        • 2016-12-07
        相关资源
        最近更新 更多