Hi Mohamed,
This should get your date of retirement. Just use the DateDiff function to calculate your total days, months, years:
Sub RetirmentDate(datDateOfBirth As Date)
Dim datRetirementFlag As Date
Dim datDateOfRetirement As Date
datRetirementFlag = DateAdd("yyyy", 60, datDateOfBirth)
If (datDateOfBirth = FirstDayofMonth(datDateOfBirth)) Then
datDateOfRetirement = LastDayofPreviousMonth(datRetirementFlag)
Else
datDateOfRetirement = LastDayofMonth(datRetirementFlag)
End If
Debug.Print datDateOfRetirement
End Sub
Function FirstDayofMonth(datDOB As Date)
FirstDayofMonth = DateAdd("d", 1 - DatePart("d", datDOB), datDOB)
End Function
Function LastDayofPreviousMonth(datRF As Date)
LastDayofPreviousMonth = (DateAdd("d", 1 - DatePart("d", datRF), datRF)) - 1
End Function
Function LastDayofMonth(datRF As Date)
LastDayofMonth = DateSerial(DatePart("yyyy", datRF), DatePart("m", datRF) + 1, 1) - 1
End Function
HTH,
Bob
|