Issues with the dates in the code

Hello, I’m new to grafana I need help. I want to receive the value from a water sensor. I want to calculate the average water usage from 3 AM to 5 AM of the previous day. For example, today is the 8th, and I want to know how much water was used from 3 AM to 5 AM on the 7th.

I have a code, but it’s changing over time. If the reading was taken yesterday, it doesn’t make sense for it to change; it should be a fixed value. Not only is it giving me the wrong value, but it’s also changing with time.

SELECT MEAN(“difference”) / 1000 AS “mean_difference”
SELECT difference(last(“value”)) AS “difference”
FROM “device_frmpayload_data_counter_TOTAL”
WHERE “dev_eui” = ‘0600d4d4da8f8680’
AND time >= (now() - 1d) - (now() - now() + 5h)
AND time < (now() - 1d) - (now() - now() + 3h)
GROUP BY time(1d) fill(none)
GROUP BY time(1d);