Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
870 views
in Technique[技术] by (71.8m points)

sql - How to convert time in seconds to HH:MM:SS format in 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...