24 hours of values

后端 未结 3 1743
离开以前
离开以前 2021-01-25 17:38

I have a sql table : date (Y-m-d) / time (00:00:00) / power (INT)

When I select a date from an inline datepicker, I am trying to post 3 HighCharts graph (one-24 hours, t

3条回答
  •  不思量自难忘°
    2021-01-25 18:04

    At the moment, your SELECT gives you only the results which happened exactly 24 hours before the current moment. What you need is a range. Example for 1 hour (indentation added for clarity):

    WHERE `time` BETWEEN 
       DATE_SUB('".$choice."', INTERVAL 24 HOUR) 
       AND DATE_SUB('".$choice."', INTERVAL 23 HOUR) 
    

    This way, you'll get results with time in the 1-hour range of "now - 24 hours" and "now - 23 hours". The BETWEEN operator is equivalent to this:

    WHERE `time` >= DATE_SUB('".$choice."', INTERVAL 24 HOUR)
       AND `time` <= DATE_SUB('".$choice."', INTERVAL 23 HOUR) 
    

提交回复
热议问题