gpt4 book ai didi

php - 如何找到 start_time 和 end_time 范围,如果在范围内找到然后检查 start_date 和 end_date

转载 作者:行者123 更新时间:2023-11-29 07:24:41 24 4
gpt4 key购买 nike

我在数据库中有一个下表。

    id | list_id |venue_id |name | start_date | end_date   |start_time | end_time 
1 | 1 | 1 |asdf | 2019-02-02| 2019-02-28 |05:30 |10:00
2 | 7 | 2 |awed | 2019-02-10| 2019-02-20 |07:30 |14:00
3 | 7 | 1 |mjgd | 2019-02-04| 2019-02-13 |09:30 |18:00

现在,我必须在 2019-02-042019-03-01< 之间找到 venue_id=1 的开始日期和结束日期。所以我使用了下面的查询。

SELECT * FROM `batch_list` WHERE `venue_id` = 1 and ((start_date between '2019-02-04' and '2019-03-01') OR (end_date between '2019-02-04' and '2019-03-01'))

现在我必须找到 venue_id=1 的日期和时间,范围是 2019-02-042019-03-0105:0018:00。所以我尝试了下面的查询

SELECT * FROM `batch_list` WHERE `venue_id` = 1 and ((start_date between '2019-02-04' and '2019-03-01') OR (end_date between '2019-02-04' and '2019-03-01')) and((start_time <= `end_time`) and (`start_time` between '05:00' and '18:00')and (end_time between '05:00' and '18:00'))

所以到目前为止没有问题。

我的时间是 05:0020:00 然后我得到与 venue_id 1 相关的所有记录但是如果我改变时间10:0013:00 然后我没有得到记录。

我需要查明该范围内是否有可用的开始时间和结束时间。如果找到,则检查开始日期和结束日期。

你能帮我解决这个问题吗?

模型

function fetchBatches($venue_id,$new_batch_start_date,$new_batch_end_date,$new_batch_start_time,$new_batch_end_time)
{
$where="batch_venue_id='$venue_id' and ((start_date between '$new_batch_start_date' and '$new_batch_end_date')OR (end_date between '$new_batch_start_date' and '$new_batch_end_date')) and ((start_time<=end_time) and (start_time < '$new_batch_start_time' and start_time < '$new_batch_end_time'))";

$result =$this->db->select('*')
->from('batch_list')
->where($where)
->get()
->result();
if ($result) {
return $result;
}
else{
return 0;
}

}

最佳答案

正如一些人所建议的,最好将日期和时间合并到数据库中。

对于你的问题,我想你想要的查询是这个:

SELECT * FROM batch_list 
WHERE venue_id = 1
AND (start_date <= '2019-03-01')
AND (start_time <= '13:00:00')
AND (end_date >= '2019-02-04')
AND (end_time >= '10:00:00')

关于php - 如何找到 start_time 和 end_time 范围,如果在范围内找到然后检查 start_date 和 end_date,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54485305/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com