Search code examples
mysqlsqlunix-timestamp

How to convert unix epoch format date to UTC in SQL query?


I am having this format of datetime 1610382439.I am looking sql query to convert it to UTC time.


Solution

  • One solution is to add those seconds to 1970-01-01. The datetime datatype does not adjust for DST:

    select cast('1970-01-01' as datetime) + interval 1610382439 second
    -- 2021-01-11 16:27:19