Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Time difference Post Reply Post New Topic
Author Message
iami21
Newbie
Newbie


Joined: 20 Jul 2009
Online Status: Offline
Posts: 11
Quote iami21 Replybullet Topic: Time difference
     Posted: 23 Jul 2009 at 9:41pm
how do i get the time difference that will output in this format?

00Day 00Hrs 00Min 00Sec

i am not sure if datediff can combine all three. i've tried doing datediff in days,hrs,mins,secs separately then create another formula to combine all four,but apparently the logic is wrong since if timeStart is 10:45AM and timeEnd is 1100AM, it will give me 0Day 1Hr 45Min, which is really wrong.  Anyone have any ideas? Your help will be very much appreciated!Thanks in advance!
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 24 Jul 2009 at 7:05am
local numbervar sec:=datediff(s,{table.start}, {table.end});
local numbervar day:=0;
local numbervar hr:=0;
local numbervar min:=0;
local numbervar calc;
calc:=truncate(sec/(24*3600);
day:=calc;
sec:=sec-calc*(24*3600);
calc:=truncate(sec/3600);
sec:=sec-calc*(3600);
calc:=truncate(sec/60);
min:=calc;
sec:=sec-calc*(sec/60);
 
totext(day,0"")+"Day "+totext(hr,0"") +"Hrs "+totext(min,0"")+"Min "+totext(sec,0"")+"Sec"
 
you may need to change the local variable names as they might be reserved, but this should work.
IP IP Logged
iami21
Newbie
Newbie


Joined: 20 Jul 2009
Online Status: Offline
Posts: 11
Quote iami21 Replybullet Posted: 26 Jul 2009 at 10:56pm
hey thanks! it worked , but i made a few changes in the formula. i'll include it here for the others.

local numbervar sec:=datediff("s",{ORD_SPL.OS_SPL_RCVDT},{ORD_DTL.OD_VALIDATE_ON});
local numbervar day:=0;
local numbervar hr:=0;
local numbervar min:=0;
local numbervar calc;

calc:=truncate(sec/(24*3600));
day:=calc;

calc:=truncate(sec/3600);
hr:=calc;

calc:=truncate(sec/60);
min:=calc;

sec:=sec mod 60;
 
totext(day)+"Day "+totext(hr) +"Hrs "+totext(min)+"Min "+totext(sec)+"Sec"

in the formula you gave in the previous post , i would just like to know, what does this do totext(day,0"")? i removed the 0"" in the revision i made bec. it will give an error when i execute the formula.

thanks!
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 27 Jul 2009 at 6:02am
oops, should have been totext(day,0,"")
look in help...teach a man to fish...
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