1

我想获得从 12:00:00 PM 到 02:00:00 PM 的时间,但是当我使用start_time >= '12:00:00' AND end_time <= '02:00:00'. 到目前为止我有这个代码。
注意:我正在使用 Code Igniter。

    $start =  date("g:i:s", strtotime($this->input->post('start')));
    $end =  date("g:i:s", strtotime($this->input->post('end')));
    $date_reserve =  $this->input->post('date_reserve');

    $sql = "SELECT materialID FROM schedule WHERE date_reserve = ? AND start_time >= ? AND end_time <= ?";
    $query = $this->db->query($sql,array($date_reserve,$start,$end));

g:i:s习惯将其格式化为 12 小时时间格式。当我尝试回应它时,给了我12:00:00并且02:00:00它没有得到AM/PM. 我的数据库中 start_time 和 end_time 的数据类型也是time. 什么是检索数据的正确方法以及我应该在我的数据库中使用什么数据类型。谢谢!。

4

1 回答 1

0

假设您DATETIME在数据库中使用 -format 作为数据类型,这应该可以帮助您:

$start =  date("h:i:s", strtotime($this->input->post('start')));
$end =  date("h:i:s", strtotime($this->input->post('end')));
...
$sql = "SELECT materialID FROM schedule WHERE date_reserve = ? AND TIME(start_time) >= ? AND TIME(end_time) <= ?";

编辑: 因此,如果您使用TIME-format,您只需更改要插入的值的格式:

$start =  date("h:i:s", strtotime($this->input->post('start')));
$end =  date("h:i:s", strtotime($this->input->post('end')));
于 2013-08-30T11:21:13.213 回答