Date Applications

kenone

New member
Joined
Aug 24, 2006
Messages
1
Programming Experience
Beginner
My development environment: vb.net 2002,MSSQL Server2000,Windows2000,I am developing a pension application that should calculate monthly pensions amount and Gratuity (lumpsum)amount for Pensioners in an organisation.There was some scenarios regarding date in calculating Period in Service that I could not accomodate in my code(am not so good in vb.net).This calculation uses hire date and retire date to calculate service period for an employee.Service period is then used to calculate monthly pensions and Gratuity amount.
Below is my code to handle date calculations to get a service period,however it didnt accomodate other scenarios;

VB.NET:
Dim endDate,endYear As DateTime = RetireDate.Value
Dim startYear,startDate As DateTime = HireDate.Value
 
Dim months As Integer = (endDate.Year - startDate.Year) * 12 + (endYear.Month - startYear.Month)
txtServicePeriod.Text = months
This code works just as well in normal circumstances.I want to accomodate the following three scenarios;
1.If the Hire date is from 1st - 15th,should be considered as the whole month in the Service period calculation.Currently the whole month in question is being excluded.
Live example;
hiredate 01/12/1978 - retire date 30/06/2006 using the above calculation you will get 330 months,but in real sense it should be 331 months(plus december itself).

2.Incase the first employment terms is temporary,then this period should be divided into two (its regarded as a half service period).Plus the Full time period(After he/she becomes permanent employee).
eg.hire date on temporary terms 15/10/1980 - 15/10/1984 then on
permanent terms 20/10/1984 - 20/08/2006.Service period should be (15/10/1980 to 15/10/1984) /2 plus the permanent service period.

3.If there is any broken service period during the employment( when someone not in service for any reason),this should be deducted automatically from total service period.Note that, among others,to serve this purpose i have two tables,namely pensioners and brokenservice .I dont know how i can handle this situation.
I am sorry for the lengthy post,but its due to my lack of vb.net expertise.
I will apppreciate your support
Thanks in advance
 
Last edited by a moderator:
Dim TempDate AsNewDate(1986, 2, 28)
Dim StartDate AsNewDate(1986, 8, 1)
Dim EndDate AsNewDate(2006, 9, 6)
Dim BrokenPeriod1Start AsNewDate(1990, 1, 1) 'Use an array and a loop for these, this is just an example
Dim BrokenPeriod1End AsNewDate(1990, 7, 1)
Dim BrokenPeriod2Start AsNewDate(1997, 1, 1)
Dim BrokenPeriod2End AsNewDate(1997, 3, 1)
'First add up your total months
Dim TotalMonths AsInteger = 0
'Add the half sevice months for the temp period
'IIf(TempDate.Day < 16, 1, 0)) <--- this covers your additional month if the startdate is in the first half of the month
TotalMonths += ((StartDate.Year - TempDate.Year) * 12 + (StartDate.Month - TempDate.Month) + IIf(TempDate.Day < 16, 1, 0)) / 2
'Add the full time service months
TotalMonths += (EndDate.Year - StartDate.Year) * 12 + (EndDate.Month - StartDate.Month)
'Now add up your broken service period months
Dim TotalBrokenMonths AsInteger = 0
'You will probably need to use an array and a loop for this bit
TotalBrokenMonths += (BrokenPeriod1End.Year - BrokenPeriod1Start.Year) * 12 + (BrokenPeriod1End.Month - BrokenPeriod1Start.Month)
TotalBrokenMonths += (BrokenPeriod2End.Year - BrokenPeriod2Start.Year) * 12 + (BrokenPeriod2End.Month - BrokenPeriod2Start.Month)
'Finally get the final number of working months
Dim FinalServicePeriod AsInteger = TotalMonths - TotalBrokenMonths



I hope that helps :)

P.S. i expect some rep for that one :p
 

Latest posts

Back
Top