Xuân Thanh > 04-10-12, 04:52 PM
Function ThamNien(StartDate As Date, EndDate As Date) As Long
Dim SoNam As Long
If EndDate - StartDate < 0 Then MsgBox "Khong tinh duoc tham nien", , "Thong Bao": ThamNien = 0: Exit Function
If Day(StartDate) = Day(EndDate) And Month(StartDate) = Month(EndDate) Then
SoNam = Year(EndDate) - Year(StartDate)
ElseIf Day(StartDate) = Day(EndDate) And Month(StartDate) < Month(EndDate) Then
SoNam = Year(EndDate) - Year(StartDate)
ElseIf Day(StartDate) = Day(EndDate) And Month(StartDate) > Month(EndDate) Then
SoNam = Year(EndDate) - Year(StartDate) - 1
ElseIf Day(StartDate) < Day(EndDate) And Month(StartDate) = Month(EndDate) Then
SoNam = Year(EndDate) - Year(StartDate)
ElseIf Day(StartDate) > Day(EndDate) And Month(StartDate) = Month(EndDate) Then
SoNam = Year(EndDate) - Year(StartDate) - 1
End If
ThamNien = SoNam
End Function