dimanche 25 août 2019

Need equivalent for (non-existent) whereHour command in Laravel

I use the following SQL query to return a set of data (upcoming sessions):

SELECT * FROM availabilities 
WHERE 
name = "Booked"
and 
start_time >= (DATE_ADD(NOW(), INTERVAL 1 DAY))
and
DAY(start_time) >= (DAY(DATE_ADD(NOW(), INTERVAL 1 DAY)))
and
HOUR(start_time) = (HOUR(DATE_ADD(NOW(), INTERVAL 1 HOUR)));

This returns the data I need (upcoming sessions 24 hours in advance) but I am struggling to get this into a format that can return the same data in Laravel (using 5.3).

I have this as a start:

$UpcomingSessions = Availability::where('name', '=', 'booked')
->where("start_time",">=", '(DATE_ADD(NOW(), INTERVAL 1 DAY))')
->whereDay("start_time",">=", '(DAY(DATE_ADD(NOW(), INTERVAL 1 DAY)))')
->where("start_time",">=", '(DATE_SUB(NOW(),INTERVAL 1 HOUR))')
->get();

But can't figure out what to do with the hour part as there is no

whereHour 

in Laravel.

If I try:

->where("HOUR(start_time)",">=", '(HOUR(DATE_ADD(NOW(), INTERVAL 1 DAY)))')

I get the following message:

Column not found: 1054 Unknown column 'HOUR(start_time)' in 'where clause'

Is there an equivalent command for whereHour that I could use perhaps? Any ideas on how to format the SQL correctly would be great!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire