我正在研究一个预订系统,只需要选择今天某个字段的记录。不是今天和将来,而是今天。
查询当前为:
$advancedBookings = Booking::where('type', 2)
->whereNull('estimated_booking_time')
->where('requested_booking_time', ?????);
$advancedBookings->get();
requested_booking_time是我希望检查的字段,存储的日期采用以下格式:
2017-08-23 08:00:00
所以我只想选择与当天在同一天的行。
据我了解,你想要今天创建的记录;然后只得到今天的日期。
$today = date("Y-m-d");
现在您的查询是这样的。
$advancedBookings = Booking::where('type', 2)
->whereNull('estimated_booking_time')
->where('requested_booking_time', $today)->get();
您可以使用whereDate
并使用Carbon
格式设置日期:
$advancedBookings = Booking::where('type', 2)
->whereNull('estimated_booking_time')
->whereDate('requested_booking_time', '=' , Carbon::today()->toDateString());
$advancedBookings->get();
或者使用Carbon
格式化查询前的日期。
你应该试试这个:
$advancedBookings = Booking::where('type', 2)
->whereNull('estimated_booking_time')
->whereDate('requested_booking_time', '=', date('Y-m-d'))
->get();