Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Formatting a Sum of Time Post Reply Post New Topic
Author Message
MichelleM
Newbie
Newbie
Avatar

Joined: 22 Nov 2011
Online Status: Offline
Posts: 5
Quote MichelleM Replybullet Topic: Formatting a Sum of Time
     Posted: 22 Nov 2011 at 8:37am

I created a report to sum the number of hours, minutes, seconds an agent is in a specific status.  I have a formula created that will add correctly, however, the seconds will show as only 1 digit vs 2. 

Example:  Total 255:13:1
Should be:  Total 255:13:01
 
When it is a 2 digit number, it shows up fine.  Here is my formula:
 
replace(cstr(floor(Sum({AgentActivityLog.StateDuration})/3600)),".00","")
+":"+replace(cstr(floor((Sum({AgentActivityLog.StateDuration})mod 3600)/60)),".00","")
+":"+replace(cstr(floor(Sum({AgentActivityLog.StateDuration})mod 60)),".00","")
 
Any help is appreciated.  Thanks!
Michelle
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 23 Nov 2011 at 5:08am
how about:
local numbervar sa := Sum({AgentActivityLog.StateDuration});
local numbervar hr := cint(sa / 3600);
local numbervar mn := cint((sa mod 3600)/60);
local numbervar sc := sa mod 60;
local stringvar ds := totext(hr, 0,"") + ":";
ds := ds + right("0" + totext(mn, 0, ""), 2) +":"
ds := ds + right("0" + totext(sc, 0, ""), 2)
ds
 
HTH
IP IP Logged
MichelleM
Newbie
Newbie
Avatar

Joined: 22 Nov 2011
Online Status: Offline
Posts: 5
Quote MichelleM Replybullet Posted: 23 Nov 2011 at 6:54am
Forgive me, as I'm very new to building formulas in Crystal, but I paste this into my formula field and I receive an error stating:
 "A number, currency amount, boolean, date, time, date-time, or string is expected here."
 
When I click ok, the first cint is highlighted.
 
Any suggestions?
Michelle
IP IP Logged
kostya1122
Senior Member
Senior Member
Avatar

Joined: 13 Jun 2011
Online Status: Offline
Posts: 475
Quote kostya1122 Replybullet Posted: 23 Nov 2011 at 8:16am

maybe it should be like this

local numbervar sa := Sum({AgentActivityLog.StateDuration});
local numbervar hr := int(sa / 3600);
local numbervar mn := int((sa mod 3600)/60);
local numbervar sc := sa mod 60;
local stringvar ds := totext(hr, 0,"") + ":";
ds := ds + right("0" + totext(mn, 0, ""), 2) +":";
ds := ds + right("0" + totext(sc, 0, ""), 2);
ds;
IP IP Logged
MichelleM
Newbie
Newbie
Avatar

Joined: 22 Nov 2011
Online Status: Offline
Posts: 5
Quote MichelleM Replybullet Posted: 23 Nov 2011 at 8:23am
That worked!  Thank you so much!
Michelle
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 23 Nov 2011 at 11:38am
doh!
 
all executable lines (except the last) need to be terminated with a ';'
silly of me to have forgotten
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum