PHP If语句有两个时间戳[关闭]

I am trying to run a PHP if statement that says if there are more than 3600 seconds between two MySQL timestamps than do something. I think I have the IF statement written correctly but something is going on where it is always being resolved to true.

 $time1=mysqli_query($con,"SELECT time_to_sec(max(time)) as time FROM table");
 $time2=mysqli_query($con,"SELECT time_to_sec(max(time)) as time FROM table and time <>(SELECT max(time) FROM table)");


 if (($time1->fetch_object()->time) - ($time2->fetch_object()->time) > 3600);
 {
 echo $test
 }

When I run:

 echo $time1->fetch_object()->time-$time2->fetch_object()->time;

It shows the correct value that I would expect but even if its less than 3600 it still does the echo $test. Any ideas what can be causing this?

Thank you!!!

Use CASE statements, a better and efficient approach:

Select event, case when  TIMESTAMPDIFF(SECOND, last_timstamp, first_timestamp)<3600 then   `under_time` when TIMESTAMPDIFF(last_timstamp, first_timestamp)>3600 then `over_time` end case   as `duration_flag` from your_table where your_conditions

Then in your PHP you condition the output based on the queried flag.

This way you make less requests to the server, and has a cleaner query.

Maybe mysql has an old bug with TIMESTAMPDIFF, so if it doesn`t work, use this instead:

Time_To_Sec(last_timstamp) - Time_To_Sec(first_timestamp)