Take the 2-minute tour ×

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

$query = "SELECT * 
          FROM onloan
          WHERE (time > $yday)";

Thanks in advance for any help!

share|improve this question
add comment

4 Answers

up vote 0 down vote accepted


FROM onloan
share|improve this answer
Thank you so much been stuck with this for a few days now!!!!!! –  user1354895 Apr 24 '12 at 23:33
add comment

You want to use strtotime().

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

share|improve this answer
thanks this is showing the time correctly formatted although the query will not execute, any ideas? –  user1354895 Apr 24 '12 at 23:29
add comment

You could try:

select * from onloan where date(time)=date(date_sub(now(),interval 1 day));
share|improve this answer
thanks got it sorted added '' to $time –  user1354895 Apr 24 '12 at 23:32
add comment

Here's an easier SQL way of doing it.

$query = "SELECT * FROM onloan WHERE DATEDIFF(NOW(),time) <= 1";
share|improve this answer
add comment

Your Answer


