Date (Working day)

simon4amiee

Registered User.
Local time
Today, 23:47
Joined
Jan 3, 2007
Messages
109
Hi my Help is not installed on my PC at work, I just wondered when doind a formula Date + 4 = Date, I want the answer to always need the answer to fall on a weekday, weekend do not count. I need to get a due date in a report, but need it to only count the weekdays! So if it is due on Monday the above formula would show as wednesday before!

Any ideas!
 
I'm not sure I fully understood why the Due Date would be a previous date. Anyway, here's an example with comments. I'm sure if it doesn't meet your needs the logic is explained enough to be able to forge a solution.

Code:
// *************************
// * VARIABLE DECLARATIONS *
// *************************

// We require an empty date variable to hold a date calculated within the formula
dateVar dteHolder; 

// Next, we need to define the due period. As this may change with 
// the business rules, it makes sense to put it in a variable at the top of the
// formula to make it easy to change.
numberVar DuePeriod := 4; 

// ****************
// * CALCULATIONS *
// ****************

// We add the due period to the current date and store it in the date variable
dteHolder := CurrentDate + DuePeriod;

// Next, we need to determine upon which day the due date falls. Each day has a number
// assigned to it in Crystal. These are:
//      1: Sunday
//      2: Monday
//      3: Tuesday
//      4: Wednesday
//      5: Thursday
//      6: Friday
//      7: Saturday
// So, if the Due Date is 1 or 7 then we need to correct this.

// We examine the due date with a Select...Case structure. These are the rules:
//      If the due date falls on a Sunday, we add one further day to it.
//      If the due date falls on a Saturday, we add two further days to it.
//      Otherwise, there's no need to add any extra days and we return the default.

Select WeekDay(dteHolder) 

    Case 1: dteHolder + 1 // DueDate falls on Sunday. Add 1 day.
    Case 7: dteHolder + 2 // DueDate falls on Saturday. Add 2 days.
    default: dteHolder // DueDate falls on Week day. Use DueDate.

; // End Select


// End Formula
 
I have a question regarding something similar.

I have an OrderDate field that automatically puts in today's date.
I have an InvoiceDate field that has an expression for it's default value =[OrderDate]+2

I need to make sure the InvoiceDate does not fall on Saturday or Sunday.


Being new at this.... here are my specific questions....
Where exactly does the select case statement go? Should it be in the GotFocus event?
And also, when I try writing the select case in that event on the VBA code I'm getting code errors.

Thanks.
 
or another option....

What about something like...
If InvoiceDate = 7 or InvoiceDate = 1 Then

(What do I do with the then part of it.....I'm stuck on that also.?)

Thanks!
 
I think I figured it out for now. Moving on to figuring out how to avoid the holidays!
 
There was a post by KeithG that had a funciton to calucalte business days.
 
Do you have vs XI? There is a function in the repository that already calculates without holidays and without weekends.
 

Users who are viewing this thread

Back
Top Bottom