MySQL select formatted date from millisecond field

后端 未结 3 692
野的像风
野的像风 2021-02-02 09:10

I have a column in a MySQL database that contains a date as milliseconds (epoch). I want to build an SQL query that formats the date as something human readable (day, month, yea

3条回答
  •  春和景丽
    2021-02-02 09:44

    If you want to get the microsecond from a field, use %f,

    select FROM_UNIXTIME(DATE_COLUMN/1000,'%Y-%M-%d %H:%i:%s %f') from TABLE_NAME;
    
    +-------------------------------------------------------+
    | FROM_UNIXTIME(CREATETIME/1000,'%Y-%M-%d %H:%i:%s %f') |
    +-------------------------------------------------------+
    | 2016-March-18 16:02:54 342000                         |
    +-------------------------------------------------------+
    

    Source : MYSQL DATE_FORMAT

提交回复
热议问题