Print Page | Close Window

DateDiff with Date/Time (hours) excluding weekends

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=21282
Printed Date: 07 May 2024 at 3:44am


Topic: DateDiff with Date/Time (hours) excluding weekends
Posted By: crystalsonic
Subject: DateDiff with Date/Time (hours) excluding weekends
Date 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.
 
 
 
 



Replies:
Posted By: lockwelle
Date 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


Posted By: crystalsonic
Date Posted: 16 Jan 2015 at 5:44am
Ok. Thank you. I had tried with seconds. However, I am still puzzled about the weekend part.


Posted By: DBlank
Date 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)



Print Page | Close Window