Data is not coming when comparing current time between 2 times to fetch data in Laravel. Both times are saved in the database as timestamp and in query also I am using timestamp. Below is the code i wrote:-
$current_date = strtotime(date('d-m-Y H:i:s'));
$bookings = MachineBooking::with('userDetail')->where('machine_id', $machine_id)->where('time_from', '>=', $current_date)->where('time_to', '<', $current_date)->get();
"time_from" and "time_to" both timestamps are saved in bigint format in database. I entered timestamp using search option in direct database also still data did not come. Can someone please tell me where i am making mistake.
5
Answers
You not describe what database you use. But maybe you can change to
Y-m-d H:i:s
format:but
strtotime
is return int not bigint.I hope I will help you
firstly You must cast the date in Model MachineBooking
secondly
cast current date with same format of time_from and time_to
Please change your code with:
time_from
andtime_to
are formatted date not a int . But your$current_date
is int with using strtotime methodJust take strtotime method:
I think you should swap the
time_from
to<=
andtime_to
to>
, and try