In MySQL, how can we use FROM_UNIXTIME() function with format string?


Suppose if we want the output of FROM_UNIXIME() function in a particular format then we can use date format string or time format string or both in it. Following is the example of using the 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 query above, 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 query above, it is using only 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 query above, it is using both date and time format string.

Updated on: 20-Jun-2020

116 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements