繁体   English   中英

如何查看第二天是不是小时 php Laravel

[英]How to check if hour is on the next day php Laravel

我正在尝试从数据库中获取数据, if the created is today but the work_hour_end is on the next day, it will skip/ignore the data

数据是这样的:

id  |  work_hour_start  |  work_hour_end
1   |  11:00:00         |  15:00:00
2   |  21:00:00         |  03:00:00  // work hour end on the next day, end of the day is 23:59

我正在尝试像下面的代码,但仍然无法正常工作。 因为work_hour_end中没有日期。

 $attendance_in = Attendance::where('employee_id', $id)
                ->whereDate('work_hour_end', Carbon::today())
                ->whereDate('created', Carbon::today())
                ->first();

whereTime方法可用于将列的值与特定时间进行比较:

$attendance_in = Attendance::where('employee_id', $id)
               ->whereTime('work_hour_end', '<', '23:59')
               ->whereDate('created', Carbon::today())
               ->first();

正如我们可以假设的那样,如果事件发生在同一天, work_end_time将始终大于work_start_time 如果work_end_time小于或等于work_start_time ,我们可以假设事件将在第二天进行。 因此,为了确定这一点,我们必须比较同一数据库行的work_end_time and work_start_time列以获得准确的结果。

$attendance_in = Attendance::where('employee_id', $id)
                ->whereColumn('work_hour_start','>=','work_hour_end')
                ->whereDate('created', Carbon::today())
                ->first();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM