# Calculation of years, months and days

• 10-23-2012, 10:07 PM
Koviko
Calculation of years, months and days
i new to java and i have my code here..all i have to do is that i want to receive the correct years and months.if months is equal to 12months than that should be 1 year..if its 14 months 30 days than that should be 3 years 1 months..as well for my days to..

the format for display looks ok but my calculation still wrongs

my code is something like this.

Public Function NaturalLength(length As Integer ) As String
'days 0 - 60
' months 61 - 730
' years 731plus

dim length1 As string=0
dim length2 As string=0
dim length3 As string=0

If length = 0 then
Return String.Empty
end if

if length >= 731
length1=cstr(Math.Floor (length / 12))
length =(length Mod 12)
end if

If length > 60 AndAlso length < 731 Then
length2 =cstr(Math.Floor(length %12 ))
length =length % 12
end if

if length < 61 Then
length3 =cstr(length)

End If

Return (length1+" Years " +length2+ " Months " +length3 + " days")

End Function