How to convert Unix epoch time in SQLite

后端 未结 3 1525
离开以前
离开以前 2020-12-08 07:10

Could you help me convert UNIX epoch time into format yyyy-mm-dd hh:mm:ss (24h) in SQLite? (GMT+7 would be appreciated).

Example: from 13190171366

相关标签:
3条回答
  • 2020-12-08 07:22

    1319017136629 is a value in milliseconds, which is not UNIX epoch time; therefore it has to be divided by 1000 and rounded to integer seconds; only then DATE() and DATETIME() will convert.

    SELECT DATETIME(ROUND(dateColumn / 1000), 'unixepoch') AS isodate FROM tableName
    

    Converting database values to localtime is unfortunate; conversion on output is less problematic.

    The Y2038 problem might already be worth a consideration.

    0 讨论(0)
  • 2020-12-08 07:33

    SELECT DATE(ROUND(1601272453000 / 1000), 'unixepoch')

    0 讨论(0)
  • 2020-12-08 07:37

    To change the values in the database, use the UPDATE command:

    UPDATE MyTable SET MyColumn = datetime(MyColumn, 'unixepoch', 'localtime')
    
    0 讨论(0)
提交回复
热议问题