简体   繁体   English

如何在yii2中使用start_time和end_time获取MySql中已有的记录?

[英]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_timeend_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.

相关问题 Laravel 5.1获取start_time和end_time之间的行(两个不同的字段) - Laravel 5.1 Fetch Rows between start_time and end_time (two different fields) PayPal + PHP - 获取收款(开始时间/结束时间) - PayPal + PHP - Fetch incoming payments (start_time / end_time) sql使用start_time和end_time进行复杂数据排序 - sql Complex data sorting with start_time and end_time 我想要`start_time` 和`end_time` 计数如何得到这个? - I want to `start_time` and `end_time` count how can get this? 我想显示当前时间不在(column)start_time和end_time(column)之间的所有人员记录 - I want to display all personnel records that the current time is not between to the (column)start_time and end_time(column) 如果在范围内找到,如何找到 start_time 和 end_time 范围,然后检查 start_date 和 end_date - How to find the start_time and end_time range if found in the range then check start_date and end_date 获取每个日期 PHP 的 start_time 和 end_time 的总小时数? - Get total hours from start_time and end_time for each date PHP? 7个SQL行中的第一个开始时间和最后一个结束时间,仅显示1个SQL结果 - First start_time and last end_time from 7 SQL rows to show only 1 SQL result 使用 PHP 从具有 start_time 和 end_time 的多维数组中查找总小时数? - Find total hours from multi-dimensional array with start_time and end_time using PHP? 使用 MYSQL php yii2 检查开始时间和结束时间是否部分重叠? - Check if start time and end time partially overlapping using MYSQL php yii2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM