简体   繁体   English

如何根据Excel公式计算速度?

[英]How to calculate pace as per formula of Excel?

I have two columns time and distance , their values 12:00:04 AM and 0.0088626 respectively. 我有两列timedistance ,它们的值分别为12:00:04 AM0.0088626 In Excel I apply the following formula to find pace: 在Excel中,我使用以下公式来求速度:

=IFERROR(A2/(B2*1000)*1000,0)

and the answer is 12:07:31 AM . 答案是12:07:31 AM

I tried to find out pace as per above formula in PHP. 我试图按照上述公式在PHP中找出速度。 I have written PHP code: 我已经写了PHP代码:

$dis = 0.0088626;
$time =  strtotime('12:00:04 AM');
echo date('h:i:s',strtotime(($time / ($dis * 1000) * 1000)));

and the answer is 1:00:00 . 答案是1:00:00

Excel and PHP answers are different. Excel和PHP的答案是不同的。

How I can I achieve this goal? 我如何实现这个目标?

You need to use the code I showed you earlier to convert PHP's unix timestamps to Excel serialized timestamp values to use in your equation 您需要使用我之前显示的代码,将PHP的unix时间戳转换为Excel序列化的时间戳值,以便在公式中使用

$dis = 0.0088626;

$x = strtotime("12:00:04 AM");
$y = strtotime("00:00:00");

$time = ($x - $y) / 86400;

$result = ($time / ($dis * 1000) * 1000);

Then once you've calculated the result, you need to convert it back from a Excel serialized timestamp value to a unix timestamp so that you can use PHP's date function 然后,一旦计算出结果,就需要将其从Excel序列化的时间戳值转换回unix时间戳,以便可以使用PHP的date函数

$result *= 86400;
echo date('h:i:s A', $result), PHP_EOL;

which displays the answer 12:07:31 AM 显示答案12:07:31 AM

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

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