我有一个表格room_booking_datas
,其中字段checkin_time
的格式为datetime
。因此,此字段的值为2015-01-24 05:25:01
,2015-01-24 05:25:40
等。现在,我需要检查2015-01-24
的特定日期的最后一次检入数据。
$date = `2015-01-24`;
$cond['RoomBookingData.checkin_time'] = $date;
$res = $this->RoomBookingData->find('first', array('conditions' => $cond, 'order' => 'RoomBookingData.checkin_time DESC'));
但正如预期的那样,$res
显示空结果!如何获得$date
的结果?
答案 0 :(得分:1)
$date = `2015-01-24`;
$res = $this->RoomBookingData->find(
'first',
array(
'conditions' => array(
DATE('RoomBookingData.checkin_time') => $date
),
'order' => 'RoomBookingData.checkin_time DESC'
)
);
答案 1 :(得分:0)
$date = '2015-01-24 00:00:00';
$date = str_replace('-', '/', $date);
$tomorrow = date('m-d-Y H:i:s',strtotime($date . "+1 days"));
然后......
$query_array = array(
'conditions' => array('RoomBookingData.checkin_time <' => $tomorrow),
'order' => array('RoomBookingData.checkin_time DESC'),
);