Solved difference between two dates exactly (1 Viewer)

FahadTiger

Member
Local time
Tomorrow, 00:52
Joined
Jun 20, 2021
Messages
115
Hello, my Experts....
I have a function that calculates the number of years, months and days of real service for the employee.. taking into account the leap years in that period.. but I am not sure that it calculates the leap years.. Is there a proven function for this purpose with the long years? ..thanks everyone for the help
my function...
Function DateDiffExact(startDate As Date, endDate As Date) As String
Dim years As Long, months As Long, days As Long
Dim startY As Long, startM As Long, startD As Long
Dim endY As Long, endM As Long, endD As Long
startY = Year(startDate)
startM = Month(startDate)
startD = Day(startDate)
endY = Year(endDate)
endM = Month(endDate)
endD = Day(endDate)
years = endY - startY
months = endM - startM
days = endD - startD
If days < 0 Then
days = days + Day(DateSerial(endY, endM + 1, 0))
months = months - 1
End If
If months < 0 Then
months = months + 12
years = years - 1
End If
DateDiffExact = days & " /" & months & " / " & years

End Function
 

Users who are viewing this thread

Top Bottom