Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By JBelg

Thread: Calculation of years, months and days

  1. #1
    Koviko is offline Member
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Default 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

    thanks in advance
    Last edited by Koviko; 10-23-2012 at 10:08 PM. Reason: uncomplete

  2. #2
    JBelg is offline Member
    Join Date
    Oct 2012
    Posts
    36
    Rep Power
    0

    Default Re: Calculation of years, months and days

    This is visual basic code and you're in a Java programming forum.
    quad64bit likes this.

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default 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.

Similar Threads

  1. number of the days (-) days gone past
    By sh4rif in forum New To Java
    Replies: 4
    Last Post: 05-22-2012, 01:17 PM
  2. printing out months
    By droidus in forum New To Java
    Replies: 2
    Last Post: 04-12-2011, 08:14 PM
  3. Replies: 2
    Last Post: 12-29-2010, 06:30 AM
  4. Replies: 3
    Last Post: 08-11-2009, 12:18 AM
  5. Displaying 12 calendar months?
    By jaydubya in forum New To Java
    Replies: 3
    Last Post: 09-16-2008, 06:28 AM

Posting Permissions

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