Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: DateDiff with Date/Time (hours) excluding weekends Post Reply Post New Topic
Author Message
crystalsonic
Groupie
Groupie


Joined: 26 Jan 2012
Online Status: Offline
Posts: 46
Quote crystalsonic Replybullet Topic: DateDiff with Date/Time (hours) excluding weekends
    Posted: 16 Jan 2015 at 4:41am
I have the following formula defined that calculates the date difference in days and excludes weekends:
 
Local DateTimeVar d1 := (DateTimeValue ({EpisodeTests.DateAuth},{EpisodeTests.TimeAuth} ));
Local DateTimeVar d2 := (DateTimeValue ({Tracking.TrackDate},{Tracking.TrackTime} ));
DateDiff ("d", d1, d2) - DateDiff ("ww", d1, d2, crSaturday) - DateDiff ("ww", d1, d2, crSunday)
 
I need for the formula to include the time and the output shoud be in hours. I also need to exclude weekends.
 
 
 
 
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 16 Jan 2015 at 5:08am
well, if the above works for days, I would think that you just use "h" or "hour" instead of "d". Not sure about the weekend stuff, maybe it needs to multiplied by 24.

it's an idea to start with
IP IP Logged
crystalsonic
Groupie
Groupie


Joined: 26 Jan 2012
Online Status: Offline
Posts: 46
Quote crystalsonic Replybullet Posted: 16 Jan 2015 at 5:44am
Ok. Thank you. I had tried with seconds. However, I am still puzzled about the weekend part.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 16 Jan 2015 at 6:09am
if none of your start and end points can be on a saturday or a sunday I would guess that you can use lockewelle's suggestion of the hour ("h") difference and then multiple parts 2 and 3 of the formula by 24
This is a guess so test it out thoroughly though.
 
DateDiff ("h", d1, d2) - (DateDiff ("ww", d1, d2, crSaturday)*24) - (DateDiff ("ww", d1, d2, crSunday)*24)
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.047 seconds.