如何计算水晶报告中的小时数? [英] How to calculate sum of hours in crystal report?

查看:84
本文介绍了如何计算水晶报告中的小时数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据集中有字符串格式的总小时数(HH:MM:SS)。我想在水晶报告中计算HH:MM:SS的总和。



例如52:42:04 +20:34:04 = 73:16:08

我在函数中尝试了以下代码...但是输出是00:00: 00



我的尝试:



I have the total numbers of hours in the string format(HH:MM:SS) in dataset.I want to calculate sum of HH:MM:SS in crystal Report.

For example 52:42:04 +20:34:04 = 73:16:08
I tried the below code in function...But the Output is 00:00:00

What I have tried:

WhilePrintingRecords; 
NumberVar TotalSec :=  tonumber({TimeUsedReport.TotalHours});
NumberVar Hours   := Truncate  (Remainder ( TotalSec , 86400) / 3600) ; 
NumberVar Minutes := Truncate  (Remainder ( TotalSec , 3600) / 60) ; 
NumberVar Seconds := Remainder (TotalSec , 60) ;


Totext ( Hours ,   '00' ) +  ':' + 
Totext ( Minutes , '00' ) +  ':' + 
Totext ( Seconds , '00' ) 

推荐答案

你可以试试这个 -



创建细节中的公式将在几秒钟内转换HH:MI:SS。让我们称之为@tot_seconds。



在公式中写下这段代码 -



本地stringvar数组完成时间;

本地numbervar totalseconds;

completetime:= split({@ combinetime},: );

totalseconds:=(3600 * cdbl(completetime [1]))+(60 * cdbl(completetime [2]))+(cdbl(completetime [3]));



此公式将返回详细信息部分中显示的每条记录的总秒数。使用@combinetime替换您的字段。



总结此字段,在报告页脚部分添加上述公式的总计。现在您有总时间(以秒为单位)。



我们将这次转换回HH:MI:SS。创建一个公式并放入报告页脚。在公式中写下面的代码 -



replace(cstr(floor) (Sum({@tot_seconds})/ 3600)),。00,)

+:+ replace(cstr(floor((Sum({@tot_seconds})mod 3600 )/ 60)),。00,)

+:+替换(cstr(floor(Sum({@tot_seconds})mod 60)),。00, )



此公式的结果将以HH:MI:SS格式显示总时间。



来源: ASP.NET论坛



You may try this -

create a formula in the details that will convert the HH:MI:SS in seconds.Lets call it @tot_seconds.

write this code in the formula -

local stringvar array completetime;
local numbervar totalseconds;
completetime:=split({@combinetime},":");
totalseconds:= (3600*cdbl(completetime[1])) + (60*cdbl(completetime[2]))+(cdbl(completetime[3]));

This formula will return the total seconds for every record shown in the details section.substitute your field with the @combinetime.

Summarize this field ,add a total for the above formula in the reports footer section.Now you have the total time in seconds.

we will convert back this time to the HH:MI:SS.Create a formula and put in report footer.Write the following code in the formula -

replace(cstr(floor(Sum ({@tot_seconds})/3600)),".00","")
+ ":" + replace(cstr(floor((Sum ({@tot_seconds}) mod 3600)/60)),".00","")
+ ":" + replace(cstr(floor(Sum ({@tot_seconds}) mod 60)),".00","")

The result of this formula will show the total time in the HH:MI:SS format.

Source: The ASP.NET Forums

引用:

如果有帮助,请将其标记为解决方案。

Please, mark it as the solution if it helps.


这篇关于如何计算水晶报告中的小时数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆