• Mysql 中日期类型bigint和datetime互转


    MySql数据库中字段类型bigint 长度是10位的

    mysql> select (from_unixtime(1554047999))as datatime;
    +---------------------+
    | datatime |
    +---------------------+
    | 2019-03-31 23:59:59 |
    +---------------------+
    1 row in set

    mysql> select (unix_timestamp('2019-03-31 23:59:59'))as unixtime;
    +------------+
    | unixtime |
    +------------+
    | 1554047999 |
    +------------+
    1 row in set

    如果bigint存储的是13位,因此转换时会有乘以1000及除以1000的操作

    mysql> select (from_unixtime(1556609724438/1000))as datatime;
    +--------------------------+
    | datatime |
    +--------------------------+
    | 2019-04-30 15:35:24.4380 |
    +--------------------------+

    具体到表里面查询

    mysql> select id,tested from table_A;
    +----+------------+
    | id | tested |
    +----+------------+
    | 6 | 1554859010 |
    | 7 | 1554859194 |
    +----+------------+

    mysql> select id,from_unixtime(tested)AS tested from table_A;
    +----+---------------------+
    | id | tested |
    +----+---------------------+
    | 6 | 2019-04-10 09:16:50 |
    | 7 | 2019-04-10 09:19:54 |
    +----+---------------------+

  • 相关阅读:
    团队冲刺第一天
    第八周进度报告
    团队会议01
    《梦断代码》阅读笔记(三)
    《梦断代码》阅读笔记(二)
    《梦断代码》阅读笔记(一)
    SCRUM第六天
    SCRUM第五天
    大白话strom——问题收集(持续更新ing)
    maven环境快速搭建(转)
  • 原文地址:https://www.cnblogs.com/shisanye/p/15058079.html
Copyright © 2020-2023  润新知