Please do post your comments and suggestions for me to improve on chowdary1105@gmail.com

Sunday, August 9, 2009

Month difference PeopleCode

Function diff_months(&DATE1 As date, &DATE2 As date) Returns number;
Local integer &YEAR1 = Year(&DATE1);
Local integer &MONTH1 = Month(&DATE1);
Local integer &DAY1 = Day(&DATE1);
Local integer &YEAR2 = Year(&DATE2);
Local integer &MONTH2 = Month(&DATE2);
Local integer &DAY2 = Day(&DATE2);
If &DATE1 <= &DATE2 Then
If &DAY1 > &DAY2 Then
If &MONTH1 = 12 Then
&MONTH1 = 1;
&YEAR1 = &YEAR1 + 1;
Else
&MONTH1 = &MONTH1 + 1;
End-If;
End-If;
Else
If &DAY1 < &DAY2 Then
If &MONTH2 = 12 Then
&MONTH2 = 1;
&YEAR2 = &YEAR2 + 1;
Else
&MONTH2 = &MONTH2 + 1;
End-If;
End-If;
End-If;
Local integer &DIFF_MONTHS = 12 * (&YEAR2 - &YEAR1) + &MONTH2 - &MONTH1;
Return &DIFF_MONTHS;

End-Function;

No comments: