简体   繁体   English

SQL FLOAT至小时/分钟

[英]SQL FLOAT to Hours/Minutes

I have a float value that is derived from dates being subtracted. 我有一个浮点值,它是从减去的日期中得出的。 How do I convert this float value into minutes? 如何将此浮点值转换为分钟? Perferably if I could convert it into hours and minutes otherwise just minutes.... 如果我能将其转换为小时和分钟,否则只需几分钟。

For example here are some values I have: 例如,这里有一些值:

4.12676944443956

3.91463738425955

0.102466473770619

0.0308067515434232

0.0564043209888041

The answer to Pauls question is that these are days. 保罗的问题的答案是,这些日子已经过去了。

Assuming that these values indicate days and the precision you want to achieve is minutes. 假设这些值表示天,而您想要达到的精度为分钟。 The best possible way for you to do this would be to write a function to multiply this value with 1440 (number of minutes in a day) and round off the places past the decimal. 最好的方法是编写一个函数将此值乘以1440(一天中的分钟数),并四舍五入到小数点后的位。 I may be missing something though since the answer cannot be this simple. 我可能会缺少一些东西,因为答案不可能如此简单。

If that's days and fractions thereof, 如果那是几天及其零头,

Hours = :date_value * 24;
Minutes = :date_value * 24 * 60

Integer Hours     = trunc(:date_value * 24)
Remaining Minutes = mod(:date_value * 24, 60) 

Integer Days        = trunc(:date_value)
Remaining Int Hours = mod(:date_value, 24)
Remaining Minutes   = mod(:date_value, 24 * 60);

In Oracle, the "remainder" function is MOD(number, divisor). 在Oracle中,“余数”函数是MOD(数字,除数)。

When I do a query in SQL server to subtract two dates and cast as a float it gives me the result in days. 当我在SQL Server中执行查询以减去两个日期并将其强制转换为浮点数时,结果以天为单位。 So to convert your float to the number of minutes multiply by 1440. 因此要将浮点数转换为分钟数乘以1440。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM