Home>Article>Database> How to convert seconds to hours, minutes and seconds in mysql

How to convert seconds to hours, minutes and seconds in mysql

青灯夜游
青灯夜游 Original
2022-06-15 13:48:21 7487browse

In mysql, you can use the SEC_TO_TIME() function to convert seconds into hours, minutes and seconds, with the syntax "SEC_TO_TIME(seconds)"; the SEC_TO_TIME() function will use "00:00:00" as the base point of the current day to specify Seconds 'seconds' is converted to a time value of hours, minutes, and seconds and returned in the time format of 'hh:ii:ss'.

How to convert seconds to hours, minutes and seconds in mysql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

In mysql, you can use the SEC_TO_TIME() function to convert seconds into hours, minutes and seconds.The sec_to_time function can convert seconds into time, based on 00:00:00 of the current day.

mysql sec_to_time function introduction

sec_to_time: Convert the specified number of seconds into a time value of hours, minutes and seconds. And output in the time format of hh:ii:ss!

Syntax:

sec_to_time(seconds);

Parameters:

seconds: required. Number of seconds. Positive or negative values can be used

Note: This function converts the incoming seconds into the time from 00:00:00 of the day, 00:00:00 is the base, which is 0 seconds.

mysql sec_to_time function example

##Example 1:

select sec_to_time(3600); select sec_to_time(38600);

How to convert seconds to hours, minutes and seconds in mysql

Example 2:

Note: If the number of seconds entered is too large, it will still be displayed in the form of hourly accumulation.

select sec_to_time(386010);

How to convert seconds to hours, minutes and seconds in mysql

Summary of Mysql’s SEC_TO_TIME function

SEC_TO_TIME converts a numeric type data into corresponding time information and returns The seconds parameter is a time value converted to hours, minutes, and seconds.

SEC_TO_TIME and TIME_TO_SEC are inverse functions of each other.

[Related recommendations:

mysql video tutorial]

The above is the detailed content of How to convert seconds to hours, minutes and seconds in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn