Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Datediff functionality Post Reply Post New Topic
Author Message
slreyna
Newbie
Newbie
Avatar

Joined: 26 Mar 2013
Location: United States
Online Status: Offline
Posts: 4
Quote slreyna Replybullet Topic: Datediff functionality
    Posted: 21 Aug 2013 at 7:41am

Please, will you help me to write this formula: I need to write a formula that will take the date object is requested and the date object is fulfilled, then calcuate the days between, excluding weekends and holidays.  If the number of days between is less than three, it meets the standard.  If the number of days between is greater than three, it did not meet the standard.  If there are open objects that are not yet fulfilled, they should be marked yellow to be watched.  Any ideas are greatly appreciated! Embarrassed

Sheri
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 21 Aug 2013 at 10:47am
You might try something like this (I haven't tested this, so you may have to tweak the syntax a bit):
 
StringVar result := "Good";
DateVar checkDate;
DateVar endDate;
NumberVar numDays := 0;
BooleanVar notFulfilled := false;
 
if IsNull({myTable.FulfilledDate}) then
(
  endDate := CurrentDate;
  notFulfilled := true;
)
else
  endDate := {myTable.FulfilledDate};
else
(
  checkDate := {MyTable.RequestDate};
 While (result = "Good") and checkDate < endDate Do
 (
   checkDate := checkDate + 1;
   if DayOfWeek(checkDate) in 2 to 6 then
   numDays := numDays + 1;
   if numDays > 3 then
    if notFulfilled then
     result := "Open";
    else
     result :="Bad";
 )
);
result
 
If the result is "Bad", then it doesn't meet the standard, if it's "Open" then it needs to be watched.
 
This doesn't account for holidays, though.  The challenge is that the holiday dates change every year and are based on which country you're in.  So, Crystal doesn't have a way of identifying whether any given date is a holiday.  The only way I know of to handle this involves the creation of a "calendar" table in the database that has something like the following format:
 
CalDate          DateTime
DaySequence  Number(6, 0)
 
CalDate is, of course, the date in question.  DaySequence gets incremented according to the following rules:
 
Holidays have the same value as the preceding day.
Weekend days have the same value as the last non-holiday day before the weekend.  So, for example, looking at the first week of July 2013, you might have something that looks like this:[code]
CalDay                  DaySequence
----------------        ---------------
7/1/2013                 401
7/2/2013                 402
7/3/2013                 403
7/4/2013                 403
7/5/2013                 404
7/6/2013                 404
7/7/2013                 404
7/8/2013                 405
 
It then becomes fairly easy to write a stored function in the database to get the number of business days between two dates by subtracting the DaySequence of the first date from the DaySequence of the second date.  This function could be called in a SQL Expression in Crystal to get the value you're looking for.
 
-Dell
 
 
IP IP Logged
slreyna
Newbie
Newbie
Avatar

Joined: 26 Mar 2013
Location: United States
Online Status: Offline
Posts: 4
Quote slreyna Replybullet Posted: 21 Aug 2013 at 10:50am
Thank you very much!!  I'll get to work on it!  I very appreciate your help Star
Sheri
Sheri
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.031 seconds.