Faw*_*oor 4 zend-framework zend-db-table zend-db
我需要找到两个日期之间的所有日期; 这是开始日期和结束日期.这是我的查询,但它没有做我需要它做的事情.
在我的表中,我有列名date_created,格式如下2011-06-09 06:41:10.我想删除这部分,06:41:10所以我申请
DATE(date_created)
Run Code Online (Sandbox Code Playgroud)
之后,因为我的日期选择器采用这种格式,02/07/2012我改变了格式DATE_FORMAT().
$start_date and $end_date 是我的变量来比较和格式 02/07/2012
$select = $DB->select()
->from('sms', array(
'sms_id',
'sms_body',
'sms_sender',
'sms_recipient',
'date_created',
'sms_type'))
->where('phone_service_id = ?', $phone_service_id)
->where("DATE_FORMAT(DATE(date_created), '%m/%d/%Y') >= ?", $start_date)
->where("DATE_FORMAT(DATE(date_created), '%m/%d/%Y') <= ?", $end_date)
->order("".$option_call_log." ".$option_call_log_asc_desc);
Run Code Online (Sandbox Code Playgroud)
我在查询中缺少什么?为什么不比较$ start_date和$ end_date?
忘了$option_call_log和$option_call_log_asc_desc.
如果您的日期以MM/DD/YYYY格式发布,那么我不会让MySQL完成所有工作,而是将它们转换为YYYY-MM-DD HH:II:SS中的SS,它允许您执行MySQL中直观的基于范围的查询.所以:
$start_date_formatted = date('Y-m-d', strtotime($start_date)).' 00:00:00';
$end_date_formatted = date('Y-m-d', strtotime($end_date)).' 00:00:00';
$select = $DB->select()
->from('sms', array('sms_id','sms_body','sms_sender','sms_recipient','date_created','sms_type'))
->where('phone_service_id = ?', $phone_service_id)
->where("date_created >= ?", $start_date_formatted)
->where("date_created <= ?", $end_date_formatted)
->order("".$option_call_log." ".$option_call_log_asc_desc)
;
Run Code Online (Sandbox Code Playgroud)
(如果日期选择器中的日期实际上是DD/MM/YYYY格式,那么事情会更加繁琐.)
| 归档时间: |
|
| 查看次数: |
9418 次 |
| 最近记录: |