得到时间差:
select (unix_timestamp(now())-unix_timestamp(stime))/60 from table_name where whew_condition
mysql>select * from timeminus
+----+---------------------+
| id | stime |
+----+---------------------+
| 1 | 2011-09-21 09:30:00 |
| 2 | 2011-09-21 11:30:00 |
| 3 | 2011-09-20 00:00:00 |
+----+---------------------+
3 rows in set (0.02 sec)
# 计算id=1与id=2的时间差(分钟)
mysql>select (unix_timestamp(a.stime)-unix_timestamp(b.stime))/60 from (select
* from timeminus where id=2) a inner join (select * from timeminus where id=1) b
+------------------------------------------------------+
| (unix_timestamp(a.stime)-unix_timestamp(b.stime))/60 |
+------------------------------------------------------+
| 120.0000 |
+------------------------------------------------------+
1 row in set (0.00 sec)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)