一个需求要筛选学生请假数据 。比如筛选 时间 是3.1-3.2号。那么那些长期 比如2.1-3.1或者3.1-3.30这些数据都要显示出来
time_start请假开始日期
time_end请假结束日期
mysql:
SELECT * FROM `studentwork_leave WHERE ( `time_start` BETWEEN '2022-02-01 14:48' AND '2022-02-29 14:49' OR `time_end` BETWEEN '2022-02-01 14:48' AND '2022-02-29 14:49' ) OR ( time_start<='2022-02-21 14:48' AND time_end>='2022-02-29 14:48') )
thinkphp5里面model:
$model->where("time_start|time_end","between",[$data['time_start'],$data['time_end']]); $model->whereor('(UNIX_TIMESTAMP(time_start)<=' . strtotime($data['time_start']) . ' AND UNIX_TIMESTAMP(time_end)>=' . strtotime($data['time_end']) . ')');