2013-10-21 51 views
0

我想从现在开始一年前获取所有记录,但它不能正确工作。 Made in 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(); 

在此先感谢

+3

定义'不能精确地工作.'。 –

+0

在我的SQL中出现错误 – David

回答

0

我想这可能是更容易尝试大纪元时间,然后查询过的那个 - 例如Get epoch for a specific date using Javascript

这将日期转换为天数自1970年1月1日,然后从您可以减去365天(或使用yearInteger%4招,以找出是否是闰年)

0

更改这两行的任何尝试一次:

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

转储您的查询和调试:

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

我忘了时间戳之间添加空格=和TimeStamp> =。 我的不好。

相关问题