[英]How to fetch already existing records in MySql with start_time and end_time in yii2?
I am having tbl_batch
which has我有
tbl_batch
id
title
start_date
start_time
end_time
venue_id
created_by
In the database start_time and end_time is being saved as time()
在数据库中 start_time 和 end_time 被保存为
time()
Row:-排:-
id 1
title test
start_time 10:10
end_time 11:30
venue_id 1
start_date 2020-03-01 (Y-m-d)
created_by 1
So I would like to check if time is between start_time
and end_time
with the given start_date
.所以我想用给定的
start_date
检查时间是否在start_time
和end_time
之间。
Query I have tried :-我试过的查询:-
$model = Batch::find()->where([
'start_date' => '2020-03-01',
'venue_id' => 1
])->andWhere([
'AND',
[ '>=',
'start_time',
'10:20'
],
[ '<=',
'end_time',
'19:20'
]
]);
if($model->exists()){
echo 'Already exists in DB';
}else
{
echo 'Does not Exist';
}
This is not returning the correct output .这不是返回正确的输出。
I finally figured out :)我终于想通了:)
$time_between = Batch::find()->where([
'start_date' => '2020-03-01',
'venue_id' => 1
])->andWhere([
'OR',
[
'OR',
[
'between',
'end_time',
$model->start_time,
$model->end_time
],
[
'between',
'start_time',
$model->start_time,
$model->end_time
]
],
[
'AND',
[
'<=',
'start_time',
$model->start_time
],
[
'>=',
'end_time',
$model->start_time
]
]
]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.