Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Time between two date time fields Post Reply Post New Topic
Author Message
db3712
Groupie
Groupie
Avatar

Joined: 30 Oct 2008
Location: United States
Online Status: Offline
Posts: 44
Quote db3712 Replybullet Topic: Time between two date time fields
     Posted: 13 Dec 2012 at 7:31am

Hello... I have two date time fields.  I'm trying to figure out how to figure out the time (not date) between the two times minues weekends.  Any ideas?

 
Thanks!
IP IP Logged
yggdrasil
Senior Member
Senior Member
Avatar

Joined: 19 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 150
Quote yggdrasil Replybullet Posted: 16 Dec 2012 at 11:55pm
This is similar to what crystalsonic was asking
 
The following will give you the difference in days
 
numbervar Daydiff;
Local DateTimeVar d1 := {Date1};
Local DateTimeVar d2 := {Date2};
Daydiff := DateDiff ("d", d1, d2) -
     DateDiff ("ww", d1, d2, crSaturday) -
     DateDiff ("ww", d1, d2, crSunday);
 
To get the difference in seconds you will have to
count the number of seconds in each Saturday and Sunday which is 24 * 60 * 60 or 86400
 
numbervar Seconddiff;
Local DateTimeVar d1 := {Date1};
Local DateTimeVar d2 := {Date2};
Seconddiff := DateDiff ("s", d1, d2) -
    ( DateDiff ("ww", d1, d2, crSaturday) * 86400)  -
     (DateDiff ("ww", d1, d2, crSunday) * 86400) ;
 
Seconddiff
 
Which youi will then have to convert back to however you want to display it
 
 
 
IP IP Logged
db3712
Groupie
Groupie
Avatar

Joined: 30 Oct 2008
Location: United States
Online Status: Offline
Posts: 44
Quote db3712 Replybullet Posted: 17 Dec 2012 at 8:57am
Thank you for your response.  I appreciate it.  I'm going to press my luck and ask you an additional question and I didn't realize it when I posted my initial question.  If we post the first time locally (CST) and we are trying to figure out the time between a local time and another time that is based on the locations time zone, is there a possiblity of doing so.  I've run into the problem where the first time is local and the second time is based out in California which puts them two hours behind us.  It appears, due to time zones, that the ticket is dispatched before we even received it.  Thank you very much for your help.
IP IP Logged
yggdrasil
Senior Member
Senior Member
Avatar

Joined: 19 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 150
Quote yggdrasil Replybullet Posted: 18 Dec 2012 at 3:01am
Use DateAdd, (which can have a negative parameter to do a subtraction)
to get them both in the same time zone.
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