我有一个日期时间格式的表格,如下所示:2016-03-18 18:42:22
我希望能够在当天选择数据,这意味着2016-03-18
的所有数据。
例如,无论小时,分钟和秒钟。
我试着这样做:
$yesterdaydate = date('Y-m-d', strtotime('-1 days'));
$this->db->select("id_status, id_service, active");
$this->db->select("DATE_FORMAT(date, '%Y %m, %d') as formatted_date", FALSE);
$this->db->from('status');
$this->db->where('formatted_date', $yesterdaydate);
$this->db->order_by("date", "desc");
$query = $this->db->get();
return $query->result();
但它似乎不起作用。我有错误,表格中没有formatted_date。
答案 0 :(得分:0)
$ todaydate = date('Y-m-d',strtotime(' - 1天'));
在where where
中使用它 WHERE formatted_date
> ='$ todaydate 00:00:00'
答案 1 :(得分:0)
试试这个
$yesterdaydate = date('Y-m-d', strtotime('-1 days'));
$this->db->select("id_status, id_service, active");
$this->db->select('DATE_FORMAT(date,"%Y-%m-%d") as formatted_date');
$this->db->from('status');
$this->db->where('DATE_FORMAT(date,"%Y-%m-%d")', $yesterdaydate);
$query = $this->db->get();
return $query->result();