MySQL select formatted date from millisecond field

后端 未结 3 669
野的像风
野的像风 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:26

    Try using the FROM_UNIXTIME function like this as given in the manual

    SELECT FROM_UNIXTIME(1196440219);
     -> '2007-11-30 10:30:19'
    

    You could also use formatting like this

    mysql> SELECT FROM_UNIXTIME(UNIX_TIMESTAMP(),
        ->                      '%Y %D %M %h:%i:%s %x');
        -> '2007 30th November 10:30:59 2007'
    

提交回复
热议问题