我只是尝试使用当前日期时间插入两行,然后计算自该日期以来经过的时间。这是两次插入后我的表中的行并使用 NOW() 函数设置时间戳:
mysql> select * from pendingActivations;
+--------+------------+---------------------+
| userId | code | timestamp |
+--------+------------+---------------------+
| 2 | aaa | 2010-08-23 17:04:02 |
| 2345 | alkfjkla23 | 2010-08-23 16:59:53 |
+--------+------------+---------------------+
在插入 userId 等于 2 的行几分钟后,我执行了以下命令,希望能给我每行时间戳的经过时间。结果如下:
mysql> select userId, code, timestamp, NOW() - timestamp as elapsedSeconds from pendingActivations;
+--------+------------+---------------------+----------------+
| userId | code | timestamp | elapsedSeconds |
+--------+------------+---------------------+----------------+
| 2 | aaa | 2010-08-23 17:04:02 | 136.000000 |
| 2345 | alkfjkla23 | 2010-08-23 16:59:53 | 4585.000000 |
+--------+------------+---------------------+----------------+
我想知道第二行是如何有这么大的 elapsedSeconds 值,它表明正好过去了 1 小时 16 分 25 秒,尽管很容易看出从那以后只过去了大约 5 分钟。
这是表结构:
mysql> describe pendingActivations;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| userId | int(11) | NO | PRI | NULL | |
| code | varchar(32) | NO | UNI | NULL | |
| timestamp | datetime | NO | | NULL | |
+-----------+-------------+------+-----+---------+-------+
有什么想法和/或解释吗?