Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Substracting two date fields Post Reply Post New Topic
Author Message
aneel
Newbie
Newbie


Joined: 22 Jun 2009
Location: India
Online Status: Offline
Posts: 6
Quote aneel Replybullet Topic: Substracting two date fields
     Posted: 22 Jun 2009 at 2:48am
Hi Team,
 
I want to substract two date fields :
1) Start Date and
2) End date
 
I need the result in DD:HH:MM:SS.
 
eg: 10/06/2009 13:11:25 - 01/02/2009 12:16:59 = "Days : Hours:  Min's : Sec's.
 
Please give me a coding for creating this.
 
 
Anee Chandanam
IP IP Logged
Valmont
Newbie
Newbie
Avatar

Joined: 29 Jan 2007
Online Status: Offline
Posts: 39
Quote Valmont Replybullet Posted: 22 Jun 2009 at 4:01am
For the difference in days use:

DateTimevar dt1:= DateTime(2009, 06, 22, 12, 50, 3);
DateTimeVar dt2:= DateTime(2008, 06, 22, 12, 30, 3);
Datediff("D", dt2, dt1);

For timedifference use this:
DateTimevar dt1:= DateTime(2009, 06, 22, 12, 50, 3);
DateTimeVar dt2:= DateTime(2008, 06, 22, 12, 50, 2);
Time(dt1-dt2)

Then combine these two functions. There are dozens of ways actually. This one is ad-hoc as somebody is bugging me :)
IP IP Logged
aneel
Newbie
Newbie


Joined: 22 Jun 2009
Location: India
Online Status: Offline
Posts: 6
Quote aneel Replybullet Posted: 22 Jun 2009 at 4:38am
Thanks for your reply.
 
I want the result in the format which I have asked. But you're giving for day and time seperately.
 
Provide some other alternative.
 
Regards,
Aneel
Anee Chandanam
IP IP Logged
abhijit.raj
Newbie
Newbie


Joined: 22 Jun 2009
Location: India
Online Status: Offline
Posts: 2
Quote abhijit.raj Replybullet Posted: 22 Jun 2009 at 5:14am
Hi Aneel you can try this code..
 
NumberVar DVar := IIF((DATEDIFF("n",{PROBSUMMARYM1.OPEN_TIME},{PROBSUMMARYM1.CLOSE_TIME}) > 1440) ,(DATEDIFF("n",{PROBSUMMARYM1.OPEN_TIME},{PROBSUMMARYM1.CLOSE_TIME}) \ 1440) , 0);
Numbervar TempVar := (DATEDIFF("n",{PROBSUMMARYM1.OPEN_TIME},{PROBSUMMARYM1.CLOSE_TIME}) mod 1440);
NumberVar HVar := IIF(TempVar > 0 ,(TempVar \ 60)  , 0);
Numbervar TempVar1 := (TempVar mod 60);
NumberVar MVar := IIF(TempVar1 > 0 ,((TempVar1 * 60) \ 60)  , 0);
StringVar TimeTaken := TOTEXT(DVar,00) + ":Days " + TOTEXT(HVar,00) + ":Hours " + TOTEXT(MVar,00) + ":Minutes";
TimeTaken;
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