Calculate an age

Pierre Quentel quentel.pierre at wanadoo.fr
Sat Dec 8 12:37:13 EST 2007


On Dec 8, 10:04 am, Shane Geiger <sgei... at ncee.net> wrote:
> What is so obvious about dealing with months that vary in length and the
> leap-year issue?  Nothing.  If you were born on a day that does not
> exist every year (Feb 29th), how old are you on Feb 28th?

X years, 11 months, 28 days

or Mar 1 of
> non-leap years?

X' years, 0 month, 1 day

If you were born on Feb 29th, then you would be one
> month old on March 29th, but would you be one year, one month and one
> day old on March 29th of the next year? or would you merely be one year
> and one month old?

1 year, 1 month, 0 day ; why would there be one day more ? People born
on the 28th would be one year, one month and one day old. If two dates
have the same day-in-the-month then the difference is X years, Y
months and 0 day

I understand that there is no possible conversion from a number of
days to a (X,Y,Z) tuple of (years,months,days), and the reverse. But
the difference between 2 dates can be unambiguously expressed as
(X,Y,Z), and given a start date and an interval (X,Y,Z) you can also
find the end date unambiguously, provided the arguments are valid (for
instance, 1 month after the 30th of January is not valid)

Regards,
Pierre



More information about the Python-list mailing list