
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use FROM_UNIXTIME Function with Format String in MySQL
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.
Advertisements