Home › Forums › General Actuarial › Computer Program for Calculating Someone’s Age in Years, Months and Days
- This topic has 0 replies, 1 voice, and was last updated 7 months, 2 weeks ago by
Richard Purvey.
-
AuthorPosts
-
November 22, 2025 at 4:46 pm #25664
A Computer Program for Calculating Someone’s Age in Years, Months and Days
Written in BBC BASIC
I will start off first by showing you my 35 line basal program for calculating someone’s age in months and days;
10 INPUT d120 INPUT m1
30 INPUT y1
40 INPUT d2
50 INPUT m2
60 INPUT y2
70 IF d2>=d1 THEN months=(y2-1-y1)*12+m2+12-m1
80 IF d2>=d1 THEN days=d2-d1
90 IF d2>=d1 THEN END
100 DIM MONTHDAYMAX(12)
110 MONTHDAYMAX(1)=31
120 MONTHDAYMAX(2)=28
130 MONTHDAYMAX(3)=31
140 MONTHDAYMAX(4)=30
150 MONTHDAYMAX(5)=31
160 MONTHDAYMAX(6)=30
170 MONTHDAYMAX(7)=31
180 MONTHDAYMAX(8)=31
190 MONTHDAYMAX(9)=30
200 MONTHDAYMAX(10)=31
210 MONTHDAYMAX(11)=30
220 MONTHDAYMAX(12)=31230 IF m2=1 THEN m2=13
240 IF m2<>3 THEN GOTO 280
250 IF y2/4<>INT(y2/4) THEN GOTO 280
260 IF y2/100=INT(y2/100) AND y2/400<>INT(y2/400) THEN GOTO 280
270 MONTHDAYMAX(2)=29
280 IF MONTHDAYMAX(m2-1)+d2-d1<0 THEN GOTO 330
290 days=MONTHDAYMAX(m2-1)+d2-d1
300 IF m2=13 THEN m2=1310 months=(y2-1-y1)*12+m2+11-m1
320 END
330 months=(y2-1-y1)*12+m2+10-m1
340 days=31+MONTHDAYMAX(2)+d2-d1
350 END
Here is my 6 line leap year program, this being behind what lines 250 to 270 inclusive do.
10 INPUT y
20 X=28
30 IF y/4<>INT(y/4) THEN GOTO 60
40 IF y/100=INT(y/100) AND y/400<>INT(y/400) THEN GOTO 60
50 X=29
60 PRINT X
The first part of my 35 line basal program, lines 10 to 60 inclusive, accommodate the input of d1/m1/y1, the DOB, along with d2/m2/y2, the later date the age is to be calculated for. The days of the months should be input as numbers, for example the 5th of a month should be input as 5 and the 26th of a month should be input as 26. The months should also be input as numbers, for example February should be input as 2 and October should be input as 10. The years should be input as 4 digit numbers, for example 1900, 1901, 1926, 1982, 2000, 2006, 2025 etc.
Finally, to turn my 35 line basal program into one for calculating then printing someone’s age in years, months and days, simply add on the following 9 lines;
81 IF d2>=d1 THEN PRINT months DIV 12
82 IF d2>=d1 THEN PRINT months MOD 12
83 IF d2>=d1 THEN PRINT days
311 PRINT months DIV 12
312 PRINT months MOD 12
313 PRINT days
341 PRINT months DIV 12
342 PRINT months MOD 12
343 PRINT days
Please bear in mind that the program assumes sensible input of d1/m1/y1, the DOB, along with d2/m2/y2, the later date the age is to be calculated for.
Richard Purvey
November 2025
In memory of Morton Baxter, born 1941, died 2025, a kinder man you couldn’t meet.
P.S.
.
Back in the 1980s, in the actuarial departments and claims departments of pensions and life insurance companies, the tabulation of “rates” and “factors” for age in 1/m years at last 1/m birthday, i.e. age in complete 1/m years, or for age in 1/m years at next 1/m birthday was commonplace. For example, m=1 means age in years at last birthday, i.e. age in complete years, or age in years at next birthday, while m=12 means age in months at last 1/12 birthday, i.e. age in complete months, or age in months at next 1/12 birthday.1/m years is of course equivalent to 12/m months, and while m should be an integer, 12/m should also be an integer, meaning that the only practical values for m are 1, 2, 3, 4, 6 and 12, corresponding to 12 months, 6 months, 4 months, 3 months, 2 months and 1 month respectively.
To turn my 35 line basal program into one for calculating then printing someone’s age in 1/m years at last 1/m birthday, i.e. age in complete 1/m years, as well as age in 1/m years at next 1/m birthday, simply add on the following 11 lines;
4 INPUT m
5 A=12/m
81 IF d2>=d1 THEN B=months DIV A
82 IF d2>=d1 THEN PRINT B
83 IF d2>=d1 THEN PRINT B+1
311 B=months DIV A
312 PRINT B
313 PRINT B+1
341 B=months DIV A
342 PRINT B
343 PRINT B+1
-
AuthorPosts
- You must be logged in to reply to this topic.
