尝试将总分钟数从 datediff 转换为 Crystal 报告中的天数、剩余小时数和分钟数

Trying to convert total minutes from a datediff to days, remaining hours, & minutes in Crystal Reports

我正在使用 Crystal Reports 2013 SP5 on Windows 7 Pro 从 Oracle 数据库中提取。

我正在尝试在 crystal 中编写一个公式,报告 returns 剩余小时数的总天数如果少于 24,剩余分钟数如果少于 60 来自两个日期时间字段之间的日期差异。

到目前为止,我已经设法将总分钟数显示为天、小时和分钟:

local numbervar tm := datediff('n',{table.date1},{table.date2},0);
local numbervar h := truncate(tm/60,0);
local numbervar d := truncate(tm/1440,0);

local stringvar tm_d := totext(d,0,"") + ' days ';
local stringvar tm_h := totext(h,0,"") + ' hours ';
local stringvar tm_m := totext(tm,0,"") + ' minutes ';

local stringvar tm_string := tm_d & tm_h & tm_m

Returns: 183 天 4393 小时 263633 分钟

183 天 = 4393 小时 = 263633 分钟

我需要它做的是显示 183 天(未四舍五入)和任何剩余小时数(未四舍五入)和任何剩余分钟数(未四舍五入)所以它看起来像这样:

table.date1 和table.date2 的区别是:

183 天 4 小时 23 分钟(仅使用随机小时和分钟)

没有使用过您的系统的经验,但您肯定需要这个:

totalMinutes = 263633 
days = floor (totalMinutes /(24*60))
hours  = floor (totalMinutes %(24 * 60) /(60))
minutes = floor (totalMinutes % 60)


where % is MOD (ex: 15 MOD 4 = 3)

据我所知,floortruncate 相同,快速查找发现 MOD 与 A MOD B[= 类似 MOD 15=]

也试试这个。

local numbervar tt := datediff('n',{table.DATE1},{table.DATE2});
local numbervar d := truncate(tt/1440,0);
local numbervar h := truncate(remainder(tt,1440)/60,0);
local numbervar m := truncate(remainder(tt,60),0);
local stringvar tt_d := if d=0 then "" else totext(d,0,"") + 'd ';
local stringvar tt_h := if h = 0 then "" else (totext(h,0,"")) + 'h ';
local stringvar tt_m := totext(m,0,"") + 'm ';
local stringvar tt_string := tt_d & tt_h & tt_m

参考链接:

http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=15879

http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=10279

http://www.experts-exchange.com/Database/Reporting/Crystal_Reports/Q_24014196.html