Home > Database > Mysql Tutorial > body text

How can we use FROM_UNIXTIME() function with format string in MySQL?

WBOY
Release: 2023-08-27 14:57:10
forward
1048 people have browsed it

在 MySQL 中,我们如何使用带有格式字符串的 FROM_UNIXTIME() 函数?

Suppose if we want FROM_UNIXIME() function to output in a specific format, then we can use date format string or time format string or both in it. Below is an example of using format string in FROM_UNIXTIME() function -

mysql> Select FROM_UNIXTIME(1555033470 '%Y %M %D')AS 'Formatted Output';
+------------------+
| Formatted Output |
+------------------+
| 2019 April 12th  |
+------------------+
1 row in set (0.00 sec)
Copy after login

In the above query, it is using only date format string.

mysql> Select FROM_UNIXTIME(1555033470 '%h:%i:%s')AS 'Formatted Output';
+------------------+
| Formatted Output |
+------------------+
| 07:14:30         |
+------------------+
1 row in set (0.00 sec)
Copy after login

In the above query, it uses only the time format string.

mysql> Select FROM_UNIXTIME(1555033470, '%Y %M %D %h:%i:%s')AS 'Formatted Output';
+--------------------------+
| Formatted Output         |
+--------------------------+
| 2019 April 12th 07:14:30 |
+--------------------------+
1 row in set (0.00 sec)
Copy after login

In the above query, it uses both date and time format strings.

The above is the detailed content of How can we use FROM_UNIXTIME() function with format string in MySQL?. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!