tintu tintu - 5 months ago 13
SQL Question

Passing a computed column value to FROM_UNIXTIME in MySQL

I have a table with a column 'ts_min' having time since epoch in minutes

ts_min
--------
24429000
24428340
24427680


I tried the following query to get date representation of these values

select ts_min, from_unixtime(ts_min*60000) from mytable;


from_unixtime is returning null.

ts_min from_unixtime (ts_min * 60000)
----------------------------------------
24429000 NULL
24428340 NULL
24427680 NULL


What is the correct syntax to pass computed value from a column to from_unixtime

Answer

yes, 60 is ok. see sample:

sample

MariaDB [(none)]> select from_unixtime(24429000*60);
+----------------------------+
| from_unixtime(24429000*60) |
+----------------------------+
| 2016-06-12 16:00:00        |
+----------------------------+
1 row in set (0.00 sec)

MariaDB [(none)]>
Comments