【问题标题】:Querying UNIX date stamp for YEAR查询 YEAR 的 UNIX 日期戳
【发布时间】:2016-07-08 08:45:20
【问题描述】:

我有一个像 1474557480 这样的 UNIX 时间戳。

我需要查询WHERE这个邮票的年份是20XX

我试过了:

ee()->db->where('YEAR(cd.field_id_36)', $tour_year, FALSE);

谁能指导我这应该怎么做?

【问题讨论】:

    标签: sql codeigniter activerecord where


    【解决方案1】:

    我认为您需要先从时间戳中找出年份,如下所示:-

    $yr =  date('Y', '1474557480'); 
    

    现在你可以在 where 条件中使用这个变量了:-

    $this->db->where('cd.field_id_36', $yr);
    

    【讨论】:

    • 谢谢。我意识到我实际上只是想从列中选择年份,而不是答案。查看我修改后的问题代码。
    【解决方案2】:

    我想通了。

    ee()->db->where('YEAR(from_unixtime(cd.field_id_36))', $tour_year, FALSE);
    

    【讨论】:

      猜你喜欢
      • 2012-03-06
      • 2012-02-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-19
      相关资源
      最近更新 更多