Compute Months between dates
Terry Pickering
pickering@4j.lane.edu
Thu, 04 Sep 2003 12:06:06 -0700
Thanks much to my "distant relative" John for pointing me in the right
direction. Here is the code to compute the age at retirement. The next step
is to compute the number of months to age 65. Thanks again John.
; compute age at retirement
define d-start-date date = &
parm prompt "Date of Birth (mmddyyyy) " format mmddyyyy
define d-end-date date = &
parm prompt "Date of retirement (mmddyyyy) " format mmddyyyy
define d-start-yyyy int*4 = floor(d-start-date / 10000)
define d-end-yyyy int*4 = floor(d-end-date / 10000)
define d-start-mm int*2 = floor(mod(d-start-date,10000) / 100)
define d-end-mm int*2 = floor(mod(d-end-date,10000) / 100)
;Calculate the number of whole years:
define d-whole-years = d-end-yyyy - d-start-yyyy - 1
define d-whole-months = (12 - d-start-mm) + d-end-mm - 1
;Now add up the months:
define d-total-months int*5 = (d-whole-years * 12) + d-whole-months
;Now figure out the years and months
define t-years int*5 = floor((d-total-months/12))
define t-months int*5 = mod(d-total-months,12)
report &
tab 1 "Age at retirement:" &
tab 20 t-years pic "^^" &
tab 23 "years and" &
tab 33 t-months pic "^^" &
tab 36 "months" &
skip
set nohead
____________________________
Terry Pickering