this is a food service system... I have a table named, detalle_regimen_paciente, it stores a diet, with breakfast for monday - sunday (being 1 for monday and 7 for sunday, chilean type) that also have a specific serving time.
+---+---------+-----------+--------------+---+
|id | name |hora_carga |hora_servicio |day|
+---+---------+-----------+--------------+---+
|1 |breakfast|08:00 |09:00 |1 |
+---+---------+-----------+--------------+---+
|2 |lunch |10:00 |13:00 |1 |
+---+---------+-----------+--------------+---+
|3 |breakfast|08:00 |09:00 |2 |
+---+---------+-----------+--------------+---+
|2 |lunch |10:00 |13:00 |2 |
+---+---------+-----------+--------------+---+
so I'm struggling with the query for about two days (theres more in the db than this... some n:m relations being this a consumption table from where I can obtain the total consumption of one employee) and I found that the problem is that I cannot find a way to select just the meal for monday at 08:00 (wich is record id #1) using the current date and current time...
so in a monday at 07:58 it should return just the record with the id 1, cuz it is the next meal to serve, also the next meal to charge for the employee.
+---+---------+-------------+---+
|1 |breakfast|08:00 |1 |
+---+---------+-------------+---+
here is the sql have so far, but it seems to just filters the day...
select detalle_regimen_paciente.hora_carga
from
detalle_regimen_paciente
where
detalle_regimen_paciente.hora_servicio > CURTIME() AND
detalle_regimen_paciente.hora_carga > CURTIME()
AND
detalle_regimen_paciente.dia = (select DAYOFWEEK(CURDATE())-1)
maybe I'm just asking wrong or missusing the time functions.
pls help out here.
thx in advance.