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

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

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

#### Posting Permissions

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