# Set array of days in a month
array set dom
set birthday $xlateInVals
# Get today’s date in YYYYMMDD
set now [clock format [clock seconds] -format “%Y %m %d”]
# Separate out YYYY, MM, and DD for both the birthday and now
regexp — {(….)(..)(..)} $birthday {} byr bmo bdy
lassign $now nyr nmo ndy
# Remove leading zeros so we can do math
foreach var “byr bmo bdy nyr nmo ndy” {
set $var [string trimleft [set $var] 0]
}
# Compute days
# If Birthday days > now days the number of days is
# 0f days in last month – birthdate + now days
# also must take 1 away from months but remember 0 – 12
if {$bdy > $ndy} {
incr nmo -1
# if 0 or less set to 12 and decrement year
if {$nmo <= 0} { set nmo 12 incr nyr -1 } set nodays $dom($nmo) # Adjust for leap year if required if {$nmo == 2 && [expr {$nyr %4}]} {incr nodays} set days [expr {$nodays – $bdy + $ndy}] } else { set days [expr {$ndy – $bdy}] } # Compute months if {$bmo > $nmo} {
set months [expr {$bmo – $nmo}]
incr nyr -1
} else {
set months [expr {$nmo – $bmo}]
}
set years [expr {$nyr – $byr}]
# set age in either years month or days
set Y Y
set M M
set D D
if {$years > 0} {
set xlateOutVals $years$Y
} else {
if {$months > 0} {
set xlateOutVals $months$M
} else {
if {$days > 0} {
set xlateOutVals $days$D
} else {
set xlateOutVals N/A}
}
}