Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating work days

Status
Not open for further replies.

ginkoba

Technical User
Jan 29, 2009
60
0
0
Hi all,
I have a code that calculates the work days excluding saturdays and sundays. See code below. However, I want to further modify this so that "D1" would subtract 28 days for months 4,6,9,11 and 30 days for months 1,3,5,7,8,10,12 and so on and so forth. Please assist.


Local DateTimeVar d1 := CurrentDate-30;
Local DateTimeVar d2 := CurrentDate;
DateDiff ("d", d1, d2) -
DateDiff ("ww", d1, d2, crSaturday) -
DateDiff ("ww", d1, d2, crSunday)
 

Add another variable:

numbervar v_monthvalue;

if month(currentdate) in [4,6,9,11]
then v_monthvalue := 28
else v_monthvalue := 30;


Then modify the first line of your code to say

LocalDateTimeVar d1 := Currentdate - v_monthvalue

It looks like you missed Feb. - you probably want to add that to the list of 28 day values, or it may need its own logic.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top