Home >Database >Mysql Tutorial >How to convert hours, minutes and seconds into seconds in mysql

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

青灯夜游
青灯夜游Original
2022-06-15 12:15:354611browse

In mysql, you can use the TIME_TO_SEC() function to convert hours, minutes, and seconds into seconds. The syntax is "TIME_TO_SEC("hour:minute:second")". The TIME_TO_SEC() function accepts a time value as a parameter and converts the parameter into seconds. The conversion formula is "(hour × 3600) (minute × 60) second".

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

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

In mysql, you can use the TIME_TO_SEC() function to convert hours, minutes and seconds into seconds.

MySQL TIME_TO_SEC() function will accept a time value as a parameter, convert the parameter into seconds, and then return. The conversion formula is "(hour × 3600) (minute × 60) second".

Syntax:

TIME_TO_SEC(time)
Parameters Description
time Required. Time value

Example 1:

mysql> SELECT TIME_TO_SEC('15:15:15');

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

It can be seen from the execution results that according to the calculation formula " 15×3600 15×60 15” gives the result of seconds 54915.

Example 2:

mysql> SELECT TIME_TO_SEC('22:23:00');

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

It can be seen from the execution result that according to the calculation formula "22×3600 23×60", the result number of seconds is 80580.

[Related recommendations: mysql video tutorial]

The above is the detailed content of How to convert hours, minutes and seconds into 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