Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert time in seconds to HH:MM:SS format in MySQL?

Tags:

sql

time

mysql

I'm having a data column named test_duration bigint(12). I'm storing time in seconds into the database. Now when I fetch record from the table I want the time converted into HH:MM:SS format. How should I achieve this? Thanks in advance.

like image 210
PHPLover Avatar asked Sep 20 '13 07:09

PHPLover


1 Answers

You can use MySQL function SEC_TO_TIME().

Example:

SELECT SEC_TO_TIME(2378);

Output is:

00:39:38

So in your case:

SELECT SEC_TO_TIME(test_duration) as `Time` FORM YOUR_TABLE;
like image 106
Subedi Kishor Avatar answered Sep 28 '22 08:09

Subedi Kishor