程序代码:set date ansi
set century on
use qq.dbf
scan
d1 = 出生日期
d2 = 查体日期
nYear = year(d2)-year(d1) && 求相差年份
nMont = mont(d2)-mont(d1) && 求相差月份
if nMont < 0 && 若查体日期的月份比出生日期的月份小
nYear = nYear - 1 && 修正年份
nMont = nMont + 12 && 修正月份
endif
replace 年龄 with tran(nYear)+'岁'+tran(nMont)+'月',月龄 with tran(nYear*12 + nMont)
ENDSCAN甚至可以使用一条命令搞定:repl all 月龄 with tran((year(查体日期)-year(出生日期))*12+mont(查体日期)-mont(出生日期)),年龄 with tran(int(VAL(月龄)/12))+'岁'+tran(val(月龄)%12)+'月'









