I want to get the exact time row by second of 24 hours ago, or the row coming next of 48 hours.
Let's show you an example to understand well my goal:
Current time is: 2018-07-30 22:43:09
I have this rows in my database:
1- 2018-07-29 10:21:00
2- 2018-07-29 22:43:09
3- 2018-07-28 12:40:11
So, the expected result for this rows is:
Row number 2.
So, here next rows:
1- 2018-07-30 12:31:00
2- 2018-07-29 21:21:00
3- 2018-07-28 01:13:41
4- 2018-07-27 12:30:21
The expected result here:
Will be row number 3.
What i did ?
SELECT
`info`, `date`
FROM mytable
WHERE id='1' AND date <= DATE_SUB(NOW(), INTERVAL 24 HOUR) ORDER BY date DESC LIMIT 1
Tested my query with:
Current time: 2018-07-30 18:39:55
Rows:
1- 2018-07-30 18:42:47
2- 2018-07-29 23:16:47
3- 2018-07-29 10:41:19
Result is: Row number 2
It supposed to be, or i expect the result: Row 3.
I made an online training link here: http://rextester.com/MPXR66606
What i made wrong please ?