[MySQL] Changing UTC time to datetime


Writing time : 2014-01-28 02:09:46

Changing UTC time to datetime To change UTC time to datetime, use the FROM_UNIXTIME function.

MySQL>SELECT FROM_UNIXTIME(1452003939)  
+---------------------------+  
| FROM_UNIXTIME(1452003939) |  
+---------------------------+  
| 2016-01-05 23:25:39       |  
+---------------------------+  
1 row in set (0.00 sec)  

MySQL timestamp increases in seconds from January 1, 1970.

If the value passed is in units of one thousandth of a second, the value must be divided by 1000.
Otherwise, a NULL value is output.

MySQL> SELECT FROM_UNIXTIME(1452003939577);  
+------------------------------+  
| FROM_UNIXTIME(1452003939577) |  
+------------------------------+  
| NULL                         |  
+------------------------------+  
1 row in set (0.00 sec)  
  
  
MySQL> SELECT FROM_UNIXTIME(1452003939577 / 1000);  
+-------------------------------------+  
| FROM_UNIXTIME(1452003939577 / 1000) |  
+-------------------------------------+  
| 2016-01-05 23:25:39.5770            |  
+-------------------------------------+  
1 row in set (0.00 sec)  

Reference URL


https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

Previous post

Next post