Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: please help Post Reply Post New Topic
Author Message
rp123
Groupie
Groupie


Joined: 26 Feb 2009
Location: United States
Online Status: Offline
Posts: 47
Quote rp123 Replybullet Topic: please help
     Posted: 23 Nov 2009 at 1:40am
Hi,

I have the following formula:

datediff ("d",  {@Open Time}, {@Close Time})
&":"& datediff ("h",  {@Open Time}, {@Close Time}) MOD 24
&":"& datediff ("n",  {@Open Time}, {@Close Time}) MOD 60

when i run this formula I am getting values in the following format:

10.00:23.00:34.00

I want to eliminate the .00 values from the number and look like this:

10:23:34

if possible can you add  and make it like this:

10d:23h:34m

Please help.


rp
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 23 Nov 2009 at 6:48am

you are making a string, and CR is formating the numbers as strings and that is the default.  This should work:

totext(datediff ("d",  {@Open Time}, {@Close Time}) ,0,"")
&"d:"& totext(datediff ("h",  {@Open Time}, {@Close Time}) MOD 24,0,"")
&"h:"& totext(datediff ("n",  {@Open Time}, {@Close Time}) MOD 60,0,"") & "m"
IP IP Logged
rp123
Groupie
Groupie


Joined: 26 Feb 2009
Location: United States
Online Status: Offline
Posts: 47
Quote rp123 Replybullet Posted: 23 Nov 2009 at 8:34pm
Hi thanks a lot. The formula is working fine.

But I have one problem:

{@Open Time}:5/5/09 11:38 PM
{@Close Time}:5/6/09 06:12 PM

I get 1d:19h:27m

actually it should be 18h:27m

I dont know why it's coming 1d and 1h ahead.

can you please help me.
rp
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 24 Nov 2009 at 6:14am
This is a datediff issue...the date changed, so it says 1 day has elapsed. So the solution is..... convert to minutes and calculate from there like:
 
local numbervar totMin := datediff('m',{@open time}, {@close time});
local numbervar days := FIX(totmin/(24*60);
local numbervar hr := FIX((totmin - (days*24*60))/60);
local numbervar min := totmin MOD 60;
 
totext(days,0,"") + "d:" + totext(hr,0,"") + totext(min,0,"");
IP IP Logged
rp123
Groupie
Groupie


Joined: 26 Feb 2009
Location: United States
Online Status: Offline
Posts: 47
Quote rp123 Replybullet Posted: 25 Nov 2009 at 5:46pm
Hi,

When I ran the formula I am getting the following:

0d:00

Can you please help.
rp
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 30 Nov 2009 at 6:23am
Evidently, it looks like I missed a )
Does this work better?
 
local numbervar totMin := datediff('m',{@open time}, {@close time});
local numbervar days := FIX(totmin/(24*60));
local numbervar hr := FIX((totmin - (days*24*60))/60);
local numbervar min := totmin MOD 60;
 
totext(days,0,"") + "d:" + totext(hr,0,"") +"h:" + totext(min,0,"") +"m";
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