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!