Home  >  Article  >  Database  >  How can we use FROM_UNIXTIME() function with format string in MySQL?

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

WBOY
WBOYforward
2023-08-27 14:57:101176browse

在 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)

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)

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)

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!

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