Keith Thibodeaux Tue Oct 05 14:59:43 -0400 2010

Subject: Custom SQL Select with MySQL Timestamp column?

I'm working on a simple forum like application. I'm fighting timestamps right now (they have always been my weak spot).

Is there a simple way to add a condition to a Model::all() to only find records with a timestamp column less than X minutes old?

What I am playing around with (and isn't working - returns 0 results):

$usersonline = User::all(array('conditions' => 'DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 15 MINUTE) >= lastactivity', 'order' => 'lastactivity DESC'));

`lastactivity` is a MySQL TIMESTAMP column with a value of `YYYY-MM-DD HH:MM:SS`.

Keith Thibodeaux Sun Oct 10 16:39:55 -0400 2010

I fixed it, it was a stupid bug on my part.

Fixed with this:

$usersonline = User::all(array('conditions' => 'lastactivity >= UTC_TIMESTAMP() - INTERVAL 15 MINUTE', 'order' => 'lastactivity DESC'));

The PHP app is set to use UTC, but the server time is EST... =]