on 05-03-2013 7:56 PM
I work for a school district and am trying to create a Crystal Report (XI) to count the number of months experience teachers have - NOT including July and August
To remove the all the July months from the date range I have tried using
DateDiff ('yyyy', {StartDate},{EndDate}, 7)
but the values returned are not correct.
Here are examples of what I'm getting:
start date end date result
9/1/2012 5/31/2013 1 (incorrect, should be 0)
9/1/2007 6/30/2012 5 (incorrect, should be 4)
2/1/2002 5/31/2002 0 (correct)
Is there a way to make this work?
I finally wrapped by head around using For Loops with Arrays, and here's the solution I came up with. It's a whole lot longer but it works!
whileprintingrecords;
//COUNT SUMMER MONTHS (JULY/AUG) IN TEACHING ASSIGNMENT DATE RANGE
//create array of months in date range
Numbervar Array MnthsInAssignArray;
Redim preserve MnthsInAssignArray[datediff("m",{@AdjStartDate},{@AdjEndDate})+1];
numbervar i := i+1;
for i := 1 to (datediff("m",{@AdjStartDate},{@AdjEndDate})+1)
Do
(
MnthsInAssignArray[i] := month(dateadd("m",i,{@AdjStartDate}))-1
);
//count # of summer months in array
Local NumberVar CountMonths;
Local Numbervar j;
For j:= 1 to (datediff("m",{@AdjStartDate},{@AdjEndDate})+1)
Do
(
if MnthsInAssignArray [ j ] in[7,8] then CountMonths:= CountMonths + 1
);
CountMonths
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.