List:General Discussion« Previous MessageNext Message »
From:Don Read Date:June 18 1999 2:30am
Subject:RE: Select using time differences
View as plain text  
On 18-Jun-99 Barry wrote:
> Hi,
> 
> I could not find how to calculate the time difference between NOW() and a
> TimeStamp column using the Date Time Functions listed in the docs. I am
<snip>

> 
> Any suggestions or pointers.

mysql> show fields from log;
+-------+---------------+------+-----+-------------+----------------+
| Field | Type          | Null | Key | Default     | Extra          |
+-------+---------------+------+-----+-------------+----------------+
| seq   | int(11)       |      | PRI | 0           | auto_increment |
| login | varchar(16)   |      | PRI | nobody      |                |
| msg   | varchar(128)  |      |     | default msg |                |
| ts    | timestamp(14) | YES  |     | NULL        |                |
+-------+---------------+------+-----+-------------+----------------+
4 rows in set (0.00 sec)

mysql> select seq,login,ts from log where ts > date_sub(now(), interval 5 hour);
+------+----------+----------------+
| seq  | login    | ts             |
+------+----------+----------------+
| 4036 | admin    | 19990617212940 |
| 4037 | admin    | 19990617212950 |
| 4038 | dread    | 19990617212950 |
| 4039 | dread    | 19990617212950 |
| 4040 | dread    | 19990617212950 |
| 4041 | dread    | 19990617212951 |
| 4042 | admin    | 19990617213714 |
| 4043 | admin    | 19990618003357 |
| 4044 | admin    | 19990618005554 |
| 4045 | admin    | 19990618005651 |
| 4046 | jnmorris | 19990618005651 |
| 4047 | jnmorris | 19990618005651 |
| 4048 | jnmorris | 19990618005651 |
| 4049 | jnmorris | 19990618005653 |
+------+----------+----------------+
14 rows in set (0.02 sec)

Regards,
---
Don Read                                 dread@stripped
EDP Manager                                  dread@stripped
Calcasieu Lumber Co.                               Austin TX
-- But I'm in good company, sendmail has kicked a great many
     butts in the past
Thread
db queries suddenly slowed downDavid Johnson18 Jun
  • Select using time differencesBarry18 Jun
    • RE: Select using time differencesDon Read18 Jun
  • Re: db queries suddenly slowed downSasha Pachev18 Jun
  • Re: db queries suddenly slowed downIlya Obshadko19 Jun