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?

王林
Release: 2023-09-13 10:37:02
forward
1276 people have browsed it

检索存储在 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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template