-1

I'd like to build a query that updates daily at 1pm, which shows static data from 3pm to 11am nexy day.

if now is 2018-06-16 12pm, shows data from 2018-06-15 3pm - 2018-06-16 11am

if now is 2018-06-16 1pm, shows data from 2018-06-16 3pm - 2018-06-17 11am

Here is the query I tried.

UPDATED:

SELECT * FROM config WHERE gt BETWEEN CONCAT(curdate(),' 15:00:00') AND CONCAT(curdate()+ INTERVAL 1 DAY,' 10:59:59')

ISSUES:

When today is 2018-06-15, curdate() -> 2018-06-15, which shows data of today which no issues.

When today is 2018-06-16, curdate() -> 2018-06-16, which shows data of next day way too early, what i want is update next day 1pm daily.

Joe Go
  • 13
  • 3

3 Answers3

0

You can use this sample to build your query:

SELECT * 
FROM table_name
WHERE `date` >= NOW() - INTERVAL 10 DAY;

Here some information on how to work with INTERVAL.

And here is some useful information how to execute query at a particular time.

EDIT:

if now() = 2018-06-16 1pm, shows data from 2018-06-16 3pm - 2018-06-17 11am

Then you ca use this example:

SELECT * 
FROM config 
WHERE DATE(gt) BETWEEN DATE(NOW() + INTERVAL 2 DAY_HOUR) AND -- 2018-06-16 3pm
                       DATE(NOW() + INTERVAL 22 DAY_HOUR);   -- 2018-06-17 11am

DEMO here

Note: the first DATE should be earlier as second DATE in BETWEEN statement. Otherwise it won't work.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Andrei Suvorkov
  • 5,559
  • 5
  • 22
  • 48
0

lot of ways you can apply select command. here I mentioned the only 2 ways. this is useful for you.

SELECT * FROM config 
WHERE gt BETWEEN #07/04/1996# AND #07/09/1996#;


select * from config  where gt  and created_at > (now()- interval 10 day)
Vipin Pandey
  • 659
  • 8
  • 17
0

Two cases:

  1. It's between 0:00 and 12:59: you want yesterday 15:00 till today 11:00
  2. It's between 13:00 and 23:59: you want today 15:00 till tomorrow 11:00

The query:

select * 
from config 
where
(
  hour(current_time) between 0 and 12 
  and gt >= current_date - interval 9 hours -- yesterday 15:00
  and gt < current_date + interval 11 hours -- today 11:00
)
or
(
  hour(current_time) between 13 and 23
  and gt >= current_date + interval 15 hours -- today 15:00
  and gt < current_date + interval 35 hours -- tomorrow 11:00
);
Thorsten Kettner
  • 89,309
  • 7
  • 49
  • 73