Find Period in monthwith start date and end date..

Hi, Can somebody please help me here. Is there any function available to find the difference of two dates. I have written a function but it is not giving the value with small variations. I have the joining date and current date need to find the service of employee in HR module. The HR module we have is developed by us. Thanks & Regards, Anuchandran.C India

Hi What about a simple calculation? MESSAGE:= FORMAT(TODAY()-010703D); Message/Result is 7. Is this what you need? bye André

hi Anuchandran , I follow the method given by André Petzke. It works fine. I have used it in Fixed Asset module. WR Hari

Hi Andre, Thanks for your response. I am able to get the days but is not working for months message(’%1’,FORMAT(TODAY()-010702M)); Please advice… Best regards, Anu

Hi D1:= CurrentDate; D2:= JoiningDate; If DATE2DMY(D1,3)-DATE2DMY(D2,3) > 0 Then begin M:= DATE2DMY(calcdate('+LY',D2),2)- DATE2DMY(D2,2);// First year M:= M + (DATE2DMY(calcdate('-LY',D1),2)- DATE2DMY(D1,2));// Current year if DATE2DMY(D1,3)-DATE2DMY(D2,3) > 1 Then M:= M + ((DATE2DMY(D1,3)-DATE2DMY(D2,3))*12); end else begin M:= DATE2DMY(D2,2)- DATE2DMY(D1,2):// only current year end: Perhaps you have to add 1 to M because of the differences. bye André

Hi Andre, Thanks a lot for your time. This code is something similar to what i wrote before but the problem with this is on calculating days hence we don’t get an accurate period. Suppose we have the dates 01/01/03 as joining date and 30/02/03 as current date the above code will throw the months as 1 but it should be 2. It would be great if there is a way to use the system calender as base and do the calculations. Best regards, Anu

Hi, Just read the date 30/02/03 as 28/02/03 in the previous message or may be another case Join date : 01/03/03 Current date : 30/04/03 Thanks, Anu

Hi Anu

quote:


Originally posted by Anuc
Hi Andre, Thanks a lot for your time. This code is something similar to what i wrote before but the problem with this is on calculating days hence we don’t get an accurate period. Suppose we have the dates 01/01/03 as joining date and 30/02/03 as current date the above code will throw the months as 1 but it should be 2. It would be great if there is a way to use the system calender as base and do the calculations. Best regards, Anu


quote:


Originally posted by Andre DDB[:p]
Perhaps you have to add 1 to M because of the differences.


If this is not enough you can calculate the days from the first and the current month similar to my calculation of months in the first and the current year. bye André

Hi, Yes i already tried but with days to months looks bit complex than year to month and not coming properly in some cases. Anyway i will try this again with more conditions. Thanks a lot for your prompt response. Best regards, Anu

[:(][:(] I am still not able to get and accurate period. regards, Anu

Hi

quote:


Originally posted by Anuc
[:(][:(] I am still not able to get and accurate period. regards, Anu


IMHO it should work [;)]. What about a loop: M:=0; NextMonth:= StartDate repeat M:= M +1; NextMonth:= Calcdate('+LM+1T',NextMonth);//Note: German Date Formula until NextMonth > Currentdate; Perhaps you need some conditions for single days! bye André

[:)] let give another try . Thanks Anu

Hi Yes now i am getting it right with below code. IF (DATE2DMY(joindate,2)) > (DATE2DMY(currentdate,2)) THEN BEGIN period:=((DATE2DMY(currentdate,3))-(DATE2DMY(joindate,3)))*12-((DATE2DMY(joindate,2))-(DATE2DMY(currentdate,2))); IF (DATE2DMY(joindate,1)) > (DATE2DMY(currentdate,1)) THEN period:=period ELSE IF ((DATE2DMY(joindate,1)) <= (DATE2DMY(currentdate,1))) AND (((DATE2DMY(currentdate,1))-(DATE2DMY(currentdate,1)) >= 30)) THEN period:=period+1; END; IF (DATE2DMY(joindate,2)) < (DATE2DMY(currentdate,2)) THEN BEGIN period:=((DATE2DMY(currentdate,3))-(DATE2DMY(joindate,3)))*12+((DATE2DMY(currentdate,2))-(DATE2DMY(joindate,2))); IF (DATE2DMY(joindate,1)) > (DATE2DMY(currentdate,1)) THEN period:=period ELSE IF ((DATE2DMY(joindate,1)) <= (DATE2DMY(currentdate,1))) AND (((DATE2DMY(currentdate,1))-(DATE2DMY(currentdate,1))>=30)) THEN period:=period+1; END; IF (DATE2DMY(joindate,2)) = (DATE2DMY(currentdate,2)) THEN BEGIN period:=((DATE2DMY(currentdate,3))-(DATE2DMY(joindate,3)))*12; IF (DATE2DMY(joindate,1)) > (DATE2DMY(currentdate,1)) THEN period:=period ELSE IF ((DATE2DMY(joindate,1)) <= (DATE2DMY(currentdate,1))) AND (((DATE2DMY(currentdate,1))-(DATE2DMY(currentdate,1))>=30))THEN period:=period+1; END; END; END; … added the Code start and end. Thanks Anu