# Thread: Calculation of years, months and days

1. Member Join Date
Oct 2012
Posts
1
Rep Power
0

## 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

Last edited by Koviko; 10-23-2012 at 10:08 PM. Reason: uncomplete  Reply With Quote

2. Member Join Date
Oct 2012
Posts
36
Rep Power
0

## Re: Calculation of years, months and days

This is visual basic code and you're in a Java programming forum.  Reply With Quote

3. ## Re: Calculation of years, months and days

FYI should you need actual java code, the GregorianCalendar class does everything you need with regard to dates.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•