如何计算两个日期之间的时差 - MySql

时间:2012-02-05 20:01:38

标签: mysql

code   | user_id   | register_date | time_difference
-------+-----------+---------------+----------------
AiK4JJ | kcy2000ok | 2012-01-31    | 17:25:41
unBG1D | gktoql    | 2012-01-31    | 17:25:35
vzqeWU | gktoql    | 2012-01-31    | 17:25:32
vvkOSd | gktoql    | 2012-01-31    | 17:25:32
uwhbGt | ppsh      | 2012-01-31    | 17:25:28
unBG1D | judyssi   | 2012-01-31    | 17:25:27
vvkOSd | judyssi   | 2012-01-31    | 17:25:24

我想计算最近日期和上一日期之间的时差。

你能帮我构建MySql查询吗?

1 个答案:

答案 0 :(得分:0)

SELECT 
   UNIX_TIMESTAMP(`recent_date`)
   -
   UNIX_TIMESTAMP(`previous_date`)
AS
   `time difference`;