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