在 MySQL 中将数字 INT 以分钟为单位转换为 TIME

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20705999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:42:00  来源:igfitidea点击:

Convert number INT in minutes to TIME in MySQL

mysqlsqlconverter

提问by rodrixd

I need help, my problem is to convert an integer representing minutes into a TIME data type in MySQL example:

我需要帮助,我的问题是在 MySQL 示例中将表示分钟的整数转换为 TIME 数据类型:

 duration   -->   time
    60          01:00:00
    40          00:40:00
    30          00:30:00
   120          02:00:00

The duration column is my field in my database, I need to do a query that field turning into a time data type, in the command SELECT example:

持续时间列是我的数据库中的字段,我需要在命令 SELECT 示例中执行查询该字段转换为时间数据类型:

SELECT any_function(duration)

thanks in advance

提前致谢

回答by shadowjfaith

This should get you what you want. Multiply your minutes by 60 to get seconds then convert to time.

这应该让你得到你想要的。将分钟乘以 60 得到秒,然后转换为时间。

SELECT SEC_TO_TIME(duration*60)

SELECT SEC_TO_TIME(duration*60)

refer to http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.htmlfor time related functions in MySQL.

有关 MySQL 中与时间相关的函数,请参阅http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

回答by Nonguru

My problem was integer hours to time ie: 8.5 was 8an a half hours

我的问题是整数小时,即:8.5 was 8半小时

Use the same method as above but multiply again

使用与上述相同的方法,但再次相乘

SEC_TO_TIME((ScheduledTime*60)*60) give you 08:30:00