Home >Database >Mysql Tutorial >What is the correct way to retrieve a value stored in an INT column as a MySQL TIMESTAMP?

What is the correct way to retrieve a value stored in an INT column as a MySQL TIMESTAMP?

王林
王林forward
2023-09-13 10:37:021278browse

检索存储在 INT 列中作为 MySQL TIMESTAMP 的值的正确方法是什么?

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

For example, we have a table named 'test123', which has a column named 'val1'. In this column, we store the integer value as follows -

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

Now with the help of FROM_UNIXTIME() function, we can retrieve the column integer value 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)

The above is the detailed content of What is the correct way to retrieve a value stored in an INT column as a MySQL TIMESTAMP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete