[MySQL] Interval from date?

The Omega
Loyal Member
Joined
Dec 26, 2006
Messages
1,317
Reaction score
171
PHP:
mysql_query("DELETE FROM heartbeat WHERE when + INTERVAL 25 SECONDS < NOW()");
(the when row is a datetime row)

What am i doing wrong here?
 
I don't know mysql, but you could try these two variants.

In postgresql, it would be exactly like you did it, except with single quotes around 25 seconds:
mysql_query("DELETE FROM heartbeat WHERE when + INTERVAL '25 SECONDS' < NOW()");

In mssql, treat it like a float with 1.0 being 1 day
mysql_query("DELETE FROM heartbeat WHERE when + 25.0/60.0/60.0/24.0 < getdate()");
or
mysql_query("DELETE FROM heartbeat WHERE when + 25.0/60.0/60.0/24.0 < now()");
(25 seconds, divided by seconds in a minute, minutes in an hour, and hours in a day)
 
PHP:
mysql_query("DELETE FROM heartbeat WHERE when + INTERVAL 25 SECONDS < NOW()");
(the when row is a datetime row)

What am i doing wrong here?
Well first thing maybe it smart to explain what your trying to do...

i got a example query maybe thats helps you ..

PHP:
mysql_query("select * from `users` where `online`>DATE_ADD(NOW(), INTERVAL -5 MINUTE)");

~Passie
 
Well first thing maybe it smart to explain what your trying to do...

i got a example query maybe thats helps you ..

PHP:
mysql_query("select * from `users` where `online`>DATE_ADD(NOW(), INTERVAL -5 MINUTE)");
~Passie
Thanks, that helped me.
 
Back