Tell me how to properly implement a sample of the database at a certain time?

The task is once a day at 7 am to choose a record per day

That is, in the database values:

03/05/2015 5:00:00

03/05/2015 6:00:00

03/05/2015 07:00:00 - for this time I must see all the testimony

03/05/2015 08:00:00

03/05/2015 9:00:00

03/06/2015 6:00:00

03/06/2015 07:00:00 - then these

03/06/2015 08:00:00

03/06/2015 9:00:00

How to build the right sample? Then you need to display one value in the textbox, and not the last one, namely, at 7 am: (That's how I tried to implement it

Select * From sut.diet where datatime = DateTime('now' 7 HOUR) 

but it does not work.

    2 answers 2

    This option is suitable?

     SELECT * FROM sut.diet WHERE DATE(datetime)=CURDATE() AND HOUR(datetime)=7; 

    It will work there is a datetime field in your datetime format, not unixtime .

      A sample that can work by index (since functions from the column are not used). Actually today + 7 hours:

       select * from sut.diet where datatime = curdate()+interval 7 hour