Hi ,
I will explain.
Consider the following entries for one person.
140398 | 0.5556 | Festival Leave | 21-Apr-2019 | 21-Apr-2019 | 18-Apr-2019 | 22-Apr-2019 |
140398 | 1 | Sick Leave | 07-Aug-2019 | 07-Aug-2019 | 06-Aug-2019 | 08-Aug-2019 |
140398 | 1 | Sick Leave | 20-Aug-2019 | 20-Aug-2019 | 19-Aug-2019 | 24-Aug-2019 |
140398 | 1 | Obsolete Compensatory Leave | 21-Aug-2019 | 21-Aug-2019 | 19-Aug-2019 | 24-Aug-2019 |
140398 | 1 | Compensatory Leave | 12-Sep-2019 | 12-Sep-2019 | 11-Sep-2019 | 23-Oct-2019 |
140398 | 5 | Obsolete Compensatory Leave | 15-Sep-2019 | 19-Sep-2019 | 11-Sep-2019 | 23-Oct-2019 |
140398 | 30 | Annual Leave | 21-Sep-2019 | 20-Oct-2019 | 11-Sep-2019 | 23-Oct-2019 |
140398 | 2 | Unpaid Leave | 21-Oct-2019 | 22-Oct-2019 | 11-Sep-2019 | 23-Oct-2019 |
The last date when there was a punch before the person went on leave , as well as the earliest date when there was a punch after the person came back from leave is already available in the last two columns on the right.
We have two situations here ; the first two entries fall in the first situation where two entries are independent of each other. Here there is no problem since the gap before leave as well as the gap after leave is simple arithmetic.
The second situation is where we have multiple entries of leave with the same punch dates.
Let us take the last 4 entries , all of which have the same last punch date before leave (11-Sep-2019) and the same earliest punch date after leave (23-Oct-2019).
To get the actual gap between the punch before leave and the leave , we consider the difference between 12-Sep-2019 and 11-Sep-2019 , which is zero days for the first entry.
It can either be zero for the remaining 3 entries or it can be the difference between each of the leave start dates 15-Sep-2019 , 21-Sep-2019 and 21-Oct-2019 and the punch date before leave of 11-Sep-2019. OP will clarify this , but again the calculation is simple arithmetic.
The problem comes in calculating the gap after leave.
Since the punch date after leave is 23-Oct-2019 , and the last leave ended on 22-Oct-2019 , the
difference between these two dates is zero days.
Now , we are left with only the calculations for the days within the leave periods.
Between the ending of the first leave period on 12-Sep-2019 and the beginning of the second leave period on 15-Sep-2019 , there is no intervening punch date , and so
this is a gap of 2 days.
Between the ending of the second leave period on 19-Sep-2019 and the beginning of the third leave period on 21-Sep-2019 , there is no intervening punch date , and so
this is a gap of 1 day.
Between the ending of the third leave period on 20-Oct-2019 and the beginning of the fourth leave period on 21-Oct-2019 , there is no intervening punch date , and so
this is a gap of zero days.
If you have any doubts , please ask.
Narayan