MySQL convert seconds to datetime

Maxime picture Maxime · Aug 4, 2015 · Viewed 12.1k times · Source

So I have an integer '63605914755' like this:

SELECT TO_SECONDS( '2015-08-04 13:40:56' )
-----
Result: '63605914755'

How do I convert '63605914755' back from seconds to datetime (Ex: '2015-08-04 13:40:56') ?

Answer

Mihai Matei picture Mihai Matei · Aug 4, 2015
SELECT
  from_unixtime(seconds - to_seconds('1970-01-01 00:00:00')) as my_date_time
FROM 
  your_table

Here is an SQLFiddle