在 cakePHP 查询中更改日期格式
Change date format in cakePHP query
我有一个 table 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
的结果?
$date = `2015-01-24`;
$res = $this->RoomBookingData->find(
'first',
array(
'conditions' => array(
DATE('RoomBookingData.checkin_time') => $date
),
'order' => 'RoomBookingData.checkin_time DESC'
)
);
$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'),
);
我有一个 table 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
的结果?
$date = `2015-01-24`;
$res = $this->RoomBookingData->find(
'first',
array(
'conditions' => array(
DATE('RoomBookingData.checkin_time') => $date
),
'order' => 'RoomBookingData.checkin_time DESC'
)
);
$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'),
);