• mysq 日期相减


    mysql> desc test200;
    +---------------+----------+------+-----+---------+-------+
    | Field         | Type     | Null | Key | Default | Extra |
    +---------------+----------+------+-----+---------+-------+
    | id            | int(11)  | YES  |     | NULL    |       |
    | registerTime  | datetime | YES  |     | NULL    |       |
    | lastLoginTime | datetime | YES  |     | NULL    |       |
    +---------------+----------+------+-----+---------+-------+
    3 rows in set (0.00 sec)
    
    mysql> select * from test200;
    +------+---------------------+---------------------+
    | id   | registerTime        | lastLoginTime       |
    +------+---------------------+---------------------+
    |    1 | 2016-10-21 09:06:23 | 2016-10-21 09:06:56 |
    |    1 | 2016-10-21 09:16:11 | 2016-10-21 09:16:11 |
    +------+---------------------+---------------------+
    2 rows in set (0.00 sec)
    
    mysql> select lastLoginTime - registerTime from test200;
    +------------------------------+
    | lastLoginTime - registerTime |
    +------------------------------+
    |                           33 |
    |                            0 |
    +------------------------------+
    2 rows in set (0.00 sec)
    
    mysql> select (UNIX_TIMESTAMP(lastLoginTime) - UNIX_TIMESTAMP(registerTime)) from test200;
    +----------------------------------------------------------------+
    | (UNIX_TIMESTAMP(lastLoginTime) - UNIX_TIMESTAMP(registerTime)) |
    +----------------------------------------------------------------+
    |                                                             33 |
    |                                                              0 |
    +----------------------------------------------------------------+
    2 rows in set (0.00 sec)
    
    
    
    mysql> select now(),lastLoginTime,(UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(lastLoginTime)) from test200;
    +---------------------+---------------------+---------------------------------------------------------+
    | now()               | lastLoginTime       | (UNIX_TIMESTAMP(now()) - UNIX_TIMESTAMP(lastLoginTime)) |
    +---------------------+---------------------+---------------------------------------------------------+
    | 2016-10-21 09:32:32 | 2016-10-21 09:06:56 |                                                    1536 |
    | 2016-10-21 09:32:32 | 2016-10-21 09:16:11 |                                                     981 |
    +---------------------+---------------------+---------------------------------------------------------+
    2 rows in set (0.01 sec)

  • 相关阅读:
    [Win32]一个调试器的实现(十)显示变量
    [Win32]防止套接字被继承
    [C++]实现委托模型
    [Win32]一个调试器的实现(十一)显示函数调用栈
    [Win32]IP数据报的首部如何定义
    FMECA方法及工程应用
    C#控制台应用程序自动关闭
    ckedit 3.0 配置(一)
    [转]“余则成”教你办公室生存法则20条
    Element UI之Select选择器优化
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6199074.html
Copyright © 2020-2023  润新知