Alpha Video Training
Results 1 to 3 of 3

Thread: how to convert months in to years and months?

  1. #1
    "Certified" Alphaholic richard2007's Avatar
    Real Name
    Richard Harris
    Join Date
    Sep 2007
    Location
    Ashford, Kent, UK
    Posts
    1,095

    Default how to convert months in to years and months?

    I have a problem i can't resolve and have even struggled to try and explain it here, so i hope it makes sense.

    i am trying to write a script to duplicate an entire client record which involves a parent and a number of child records - within this script i want to determine the time difference between the date the original parent record was created and the date the case is duplicated - which i think i have achieved with this code;

    Code:
    'lookups - get values from current tables
    dim varOrigDate as D
    dim varDateDiff as N
    dim varMthDiff as N
    
    varOrigDate = lookup("[PathAlias.ADB_Path]\casefile.dbf","caseref = "+quote(session.caseref),"leaddate")
    varDateDiff = Date() - varOrigDate
    varMthDiff = varDateDiff/30

    The original record has 2 fields which hold N value for months and years at address, i need the value of varMthDiff to append to the value of the same fields in the records to be duplicated. My Problem is splitting the value of varMthDiff in to full years and the remaining months.


    hope this makes it a little clearer

    1. original record - client lived at their address for 2 yrs and 6 months
    2. its has been 2 years and 1 month since the original record was created
    3. duplicated record would show the client living at their address for 4 years and 7 months

  2. #2
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,393

    Default Re: how to convert months in to years and months?

    A slightly different approach, but thought I'd offer it anyway.

    I have more ideas, but would like to more more about what you actually have before offering them.

    Gregg


    Code:
    FUNCTION yrmo AS C (refd_beg AS D, refd_now AS D )
    dim yrcount as n
    dim mnthcount as n
    
    yrcount = year(refd_now)- year(refd_beg)
    
    if month(refd_now) >= month(refd_beg) then
        mnthcount = month(refd_now) - month(refd_beg)
        yrmo = alltrim(str(yrcount))+" Years and "+alltrim(str(mnthcount))+" Months"
    else
    	yrcount = yrcount-1
    	mnthcount = 12+month(refd_now)-month(refd_beg)
    	yrmo = alltrim(str(yrcount))+" Years and "+alltrim(str(mnthcount))+" Months"
        
    end if
    	
    END FUNCTION

  3. #3
    "Certified" Alphaholic richard2007's Avatar
    Real Name
    Richard Harris
    Join Date
    Sep 2007
    Location
    Ashford, Kent, UK
    Posts
    1,095

    Default Re: how to convert months in to years and months?

    Dear Gregg,

    sorry for not thanking you earlier, i left this to one of the last jobs, but i have used it now and it has helped with my script.

    many thanks

    richard

Similar Threads

  1. a5v10 web: Calculated grid fields for duration -(years,Months, days)
    By fineman77 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 5
    Last Post: 01-22-2012, 07:54 PM
  2. a5v10 web: Calculated grid fields for duration -(years,Months, days)
    By fineman77 in forum Alpha Five Version 10 - Desktop Applications
    Replies: 2
    Last Post: 01-20-2012, 09:16 AM
  3. Age in years and months
    By hsl9999 in forum Alpha Five Version 6
    Replies: 4
    Last Post: 10-20-2005, 10:01 PM
  4. Age in months and years
    By Edgar Lewis in forum Alpha Five Version 5
    Replies: 1
    Last Post: 02-01-2004, 09:16 PM
  5. age in months and years
    By Edgar Lewis in forum Alpha Five Version 5
    Replies: 3
    Last Post: 12-04-2002, 02:15 PM

Bookmarks

Posting Permissions

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