PHP request, get rows in the last 24 hours

I am trying to make a report that shows all the loans made on the last day. The time is saved as a timestamp in the onloan database and saved in the format yyyy-mm-dd 00:00:00. The code that I have so far shown below, but I can not format the time and -1 day correctly.

$yday  = mktime(0, 0, 0, date("m")  , date("d")-1, date("Y"));
$query = "SELECT * 
          FROM onloan
          WHERE (time > $yday)";

Thanks in advance for your help!

+3
source share
4 answers

Try

SELECT * 
FROM onloan
WHERE DATE(Time) = DATE(CAST(NOW() - INTERVAL 1 DAY AS DATE))
+1
source

You want to use strtotime().

Try $yday = date('Y-m-d h:i:s', strtotime("-1 day"))

+4
source

You can try:

select * from onloan where date(time)=date(date_sub(now(),interval 1 day));
0
source

It’s easier to use the SQL method.

$query = "SELECT * FROM onloan WHERE DATEDIFF(NOW(),time) <= 1";
0
source

All Articles