Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql select records next to current time
    text
    copied!<p>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.</p> <pre><code>+---+---------+-----------+--------------+---+ |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 | +---+---------+-----------+--------------+---+ </code></pre> <p>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...</p> <p>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.</p> <pre><code>+---+---------+-------------+---+ |1 |breakfast|08:00 |1 | +---+---------+-------------+---+ </code></pre> <p>here is the sql have so far, but it seems to just filters the day...</p> <pre><code>select detalle_regimen_paciente.hora_carga from detalle_regimen_paciente where detalle_regimen_paciente.hora_servicio &gt; CURTIME() AND detalle_regimen_paciente.hora_carga &gt; CURTIME() AND detalle_regimen_paciente.dia = (select DAYOFWEEK(CURDATE())-1) </code></pre> <p>maybe I'm just asking wrong or missusing the time functions.</p> <p>pls help out here.</p> <p>thx in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload