0

How do I query for 24 hours? start at 00.00 end at 23.59.59?

i use this query, but the result, just get last 24 hours..

mysql_query('select * from fe1b WHERE waktu_fe1b >= now() - INTERVAL 1 DAY');

The problem with that is that it gets last 24 hours. It doesn't get the from 00.00 - 23.59.59

Rich
  • 5,603
  • 9
  • 39
  • 61

5 Answers5

1

Use this Query U will get it:

mysql_query('select * from fe1b WHERE waktu_fe1b <> subdate(current_date, 1));
SenthilPrabhu
  • 661
  • 6
  • 29
1

You can use the TO_DAYS method for it. This will change a date to the days since year 0. So it will be the same for every datetime from 00:00 till 23:59 on the same day

Also I advise you to discontinue the use of mysql_query because its deprecated. See why shouldnt I use mysql functions

$query = 'select * from fe1b WHERE TO_DAYS(waktu_fe1b) = TO_DAYS(now())';
Community
  • 1
  • 1
Hugo Delsing
  • 13,803
  • 5
  • 45
  • 72
1
mysql_query('select * from fe1b WHERE waktu_fe1b >= (DATE(now()) - INTERVAL 1 DAY'));
Amir
  • 4,089
  • 4
  • 16
  • 28
0

Difficult, I had to look it up. But it seems like you can use the following code:

mysql_query("SELECT NOW(), DATE_SUB( DATE_SUB( NOW(), INTERVAL +59 SECOND), INTERVAL '+23:59' HOUR_MINUTE)")
Benz
  • 2,317
  • 12
  • 19
0

This will do the trick for selecting everything from the previous day, and is easier to maintain in my opinion:

SELECT *
FROM table
WHERE column >= CURRENT_DATE - INTERVAL 1 DAY
  AND column < CURRENT_DATE;

So for your purpose, it would be:

SELECT *
FROM fe1b
WHERE waktu_fe1b >= CURRENT_DATE - INTERVAL 1 DAY
  AND waktu_fe1b < CURRENT_DATE;
rtcherry
  • 4,840
  • 22
  • 27