PHP:
$current = time();
$time_ago = $current - 45*60; // get the time 45 mts ago.
MySQL:
I have a table status which has a datetime column ‘modified’;
I am trying to query the table to get the rows that have a modified time lower than that of $time_ago;
My PHP Code:
$this->db->select("(SELECT UNIX_TIMESTAMP(status.modified) FROM status WHERE status_id = 0) AS modified_timestamp" , FALSE);
$this->db->from('status');
$this->db->where('status_id', 0);
$this->db->where('modified_timestamp <', $time_ago);
$this->db->limit(25);
$q = $this->db->get();
Getting a db error:
Unknown column ‘modified_timestamp’ in ‘where clause’
SELECT
(SELECT UNIX_TIMESTAMP(status.modified) FROM status WHERE status_id = 0) AS modified_timestamp
FROM (status) WHERE `status_id` = 0 AND `modified_timestamp` < 1343542758 LIMIT 25
You realize you can use UNIX_TIMESTAMP() in a where clause, right?
Note: May not work as-is, I haven’t used this particular DB API, but you get the idea.