I’ve query which gives the results with a column name called alternative_time
.
It has the values like 2023-02-18 09:30:04
. I can do a query like NOW() -INTERVAL 7 DAY)
and also time range like 03:00:00
and 10:00:00
but how do i combine both to get the results of last 7 days having the time range of between ’03:00:00′ and ’10:00:00′. can i something like
T.alternative_time > NOW() -INTERVAL 7 DAY ('03:00:00' and '10:00:00')
- but this is not working.
Do we need to split the time and then store in a variable and then search with that string? can someone please help on this? Thanks!
select name
from Profile_table
and T.alternative_time > NOW() -INTERVAL 7 DAY ('03:00:00' and '10:00:00')
Tried with this but not working
2
Answers
With a bit of complex jiggling to get a string containing the right date and time and then convert that to a DATETIME you can do this
You could also just do
and forget about the conversion to a DATETIME data type
To filter results from the last 7 days with a specific time range, you can use the following query: