Syntax error What is the proper way to retrieve the value stored in INT column as MySQL TIMESTAMP?

What is the proper way to retrieve the value stored in INT column as MySQL TIMESTAMP?



We can use FROM_UNIXTIME() function to retrieve the value, as MySQL TIMESTAMP, stored as INT in the column of a table.

For example, we have a table called ‘test123’ which has a column named ‘val1’. In this column, we stored the integer values as follows −

mysql> Select * from test123;
+------------+
| val1       |
+------------+
|     150862 |
| 1508622563 |
|  622556879 |
| 2147483647 |
+------------+
4 rows in set (0.00 sec)

Now with the help of the FROM_UNIXTIME() function, we can retrieve the column integer values in the form of MySQL TIMESTAMP data.

mysql> Select FROM_UNIXTIME(Val1) from test123;
+---------------------+
| FROM_UNIXTIME(Val1) |
+---------------------+
| 1970-01-02 23:24:22 |
| 2017-10-22 03:19:23 |
| 1989-09-23 17:57:59 |
| 2038-01-19 08:44:07 |
+---------------------+
4 rows in set (0.00 sec)
Updated on: 2020-01-30T05:53:44+05:30

203 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements