我在使用 activerecord 将数据库中的日期与一周后的日期进行比较时遇到问题。我正在尝试返回开始日期不到一周后的事件列表。
event_start_date 格式为 2011-06-30 09:00:00
$this->db->select('event_id,title,event_start_date,location');
$this->db->where('event_start_date <=',DATE_ADD(NOW(),INTERVAL 7 DAYS ));
$query = $this->db->get('sd_events');
无法为此找到正确的语法,任何帮助将不胜感激:-)
最佳答案
两件事。首先,您是否尝试过将 where 子句放在引号中,如下所示:
$this->db->where('event_start_date <=','DATE_ADD(NOW(),INTERVAL 7 DAYS )');
其次,如有必要,只需跳过使用 where 函数并将整个查询放入如下所示:
$this->db->query('SELECT event_id,title,event_start_date,location FROM sd_events WHERE event_start_date <= DATE_ADD(NOW(),INTERVAL 7 DAYS )');
关于mysql - Codeigniter 数据库日期比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8829477/