[comp.lang.misc] Calculating ages

cjr@cs.bham.ac.uk (Chris Ridd <RiddCJ>) (08/17/90)

Does anyone know how to calculate a person's age in Prolog (well, any
language will do)?  We are given today's date and their birthday, and
need the answer in years, weeks and days.  We can think of various
problems with leap-years and so on, but can't find any references or
algorithms.

   Chris

-- Chris Ridd, Computer Science, Birmingham Uni, UK -- RiddCJ@Cs.Bham.Ac.Uk --

"'It's going to look pretty good, then, isn't it,' said War testily, 'the One
Horseman and Three Pedestrians of the Apocralypse.'" - Sourcery

ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) (08/20/90)

In article <982@christopher-robin.cs.bham.ac.uk>, cjr@cs.bham.ac.uk (Chris Ridd <RiddCJ>) writes:
> Does anyone know how to calculate a person's age in Prolog (well, any
> language will do)?  We are given today's date and their birthday, and
> need the answer in years, weeks and days.

Look in the book Numerical Recipes, specifically at JULDAT.
Or, if you have Quintus Prolog, use library(date).

By the way, the answer in "years, weeks, and days" is not well defined.
Presumably you mean "subtract the birth date from the last birthday,
taking that as _calendar_ years, and take weeks and days since the last
birthday".  With that definition (completed years + time since last
birthday) you only need to worry about whether the current and previous
years were leap years.

-- 
The taxonomy of Pleistocene equids is in a state of confusion.

rim@csadfa.cs.adfa.oz.au (Bob McKay) (08/20/90)

From article <982@christopher-robin.cs.bham.ac.uk>, by cjr@cs.bham.ac.uk (Chris Ridd <RiddCJ>):
> Does anyone know how to calculate a person's age in Prolog (well, any
> language will do)?  We are given today's date and their birthday, and
> need the answer in years, weeks and days.  

Unfortunately, there is no single answer as the problem is not well formulated. 
Take the example of someone born on the 28th February, 1988. What is their age 
on the 1st March, 1989? Is it:
1 year from 28/2/88 to 28/2/89 + 1 day from 28/2/89 to 1/3/89
	or
2 days from 28/2/88 to 1/3/88 + 1 year from 1/3/88 to 1/3/89
	Cheers
Bob McKay		   Phone:	+61 6 268 8169	    fax: +61 6 268 8581
Dept. Computer Science		ACSNET,CSNET:	rim@csadfa.cs.adfa.oz
Aust. Defence Force Academy	UUCP:	...!uunet!munnari!csadfa.cs.adfa.oz!rim
Canberra ACT 2600 AUSTRALIA	ARPA:	rim%csadfa.cs.adfa.oz@uunet.uu.net