tintu tintu - 2 years ago 90
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


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 Source

yes, 60 is ok. see 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)]>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download