Calculate an age

P

Pierre Quentel

Hi all,

I have searched in the standard distribution if there was a function
to return the difference between 2 dates expressed like an age :
number of years, of months and days. The difference between datetime
instances returns a timedelta object that gives a number of days, but
not an age

So is there such a function somewhere ? If not, for what reason, since
it's a rather usual task

Regards,
Pierre
 
J

John Machin

Hi all,

I have searched in the standard distribution if there was a function
to return the difference between 2 dates expressed like an age :
number of years, of months and days. The difference between datetime
instances returns a timedelta object that gives a number of days, but
not an age

So is there such a function somewhere ? If not, for what reason, since
it's a rather usual task

and a rather usually imprecisely specified task [what do you mean by
"number of months"?] with multiple interpretations/implementations/
doctrines the publication of any one of which attracts a truckload of
rotten tomatoes and derision from adherents of other sects :)
 
P

Paul McGuire

I have searched in the standard distribution if there was a function
to return the difference between 2 dates expressed like an age :
number of years, of months and days. The difference between datetime
instances returns a timedelta object that gives a number of days, but
not an age
So is there such a function somewhere ? If not, for what reason, since
it's a rather usual task

and a rather usually imprecisely specified task [what do you mean by
"number of months"?] with multiple interpretations/implementations/
doctrines the publication of any one of which attracts a truckload of
rotten tomatoes and derision from adherents of other sects :)

I think metric months are all the same length, 10**1.4834089785587095
days.

-- Paul
 
T

thebjorn

I have searched in the standard distribution if there was a function
to return the difference between 2 dates expressed like an age :
number of years, of months and days. The difference between datetime
instances returns a timedelta object that gives a number of days, but
not an age
So is there such a function somewhere ? If not, for what reason, since
it's a rather usual task

and a rather usually imprecisely specified task [what do you mean by
"number of months"?] with multiple interpretations/implementations/
doctrines the publication of any one of which attracts a truckload of
rotten tomatoes and derision from adherents of other sects :)

It may be imprecisely specified, yet it's quite useful anyway. I've
got an implementation at http://blog.tkbe.org/archive/python-how-old-are-you/
if anyone's interested..

-- bjorn
 
D

Dennis Lee Bieber

So is there such a function somewhere ? If not, for what reason, since
it's a rather usual task
Where? Other than old gravestones and some genealogy programs I've
never encountered a "common use"...

How many days in a year? 365.25 (J2000 epoch), 365.2422 [as I
recall](B1900 epoch), 365.0 (non-leap year), 366 (leap year)? Gregorian
or Julian calendar -- and depending upon one's country, the Gregorian
reform may take place at different years.

Simple months of (year/12) days, or calendrical mishmash (30 days
hath September, April, June, and November...) again with leap year
exceptions?

--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
P

Pierre Quentel

How many days in a year? 365.25 (J2000 epoch), 365.2422 [as I
recall](B1900 epoch), 365.0 (non-leap year), 366 (leap year)? Gregorian
or Julian calendar -- and depending upon one's country, the Gregorian
reform may take place at different years.

Simple months of (year/12) days, or calendrical mishmash (30 days
hath September, April, June, and November...) again with leap year
exceptions?

Hi,

I don't see where the ambiguity is. Isn't it obvious what we mean by
"I am X years, Y months and Z days" ?

Regards,
Pierre
 
M

Marc 'BlackJack' Rintsch

How many days in a year? 365.25 (J2000 epoch), 365.2422 [as I
recall](B1900 epoch), 365.0 (non-leap year), 366 (leap year)? Gregorian
or Julian calendar -- and depending upon one's country, the Gregorian
reform may take place at different years.

Simple months of (year/12) days, or calendrical mishmash (30 days
hath September, April, June, and November...) again with leap year
exceptions?

I don't see where the ambiguity is. Isn't it obvious what we mean by
"I am X years, Y months and Z days" ?

That's obvious but given either the present date or the birth date along
with that information it's not so clear what the other date may be.
Unless you give the info about the used calender systems and the points in
time (according to which calender system!?) when to use which system.

If you are just asking those questions for people living now (and are
not called Connor McLeod ;-) and the gregorian calender it's easy but
providing functions in the standard library for arbitrary date calculation
involving years is not so easy.

Ciao,
Marc 'BlackJack' Rintsch
 
S

Shane Geiger

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? or Mar 1 of
non-leap years? 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? I believe this is exactly why datetime merely states
deltas in days, not months or years.

How many days in a year? 365.25 (J2000 epoch), 365.2422 [as I
recall](B1900 epoch), 365.0 (non-leap year), 366 (leap year)? Gregorian
or Julian calendar -- and depending upon one's country, the Gregorian
reform may take place at different years.

Simple months of (year/12) days, or calendrical mishmash (30 days
hath September, April, June, and November...) again with leap year
exceptions?
I don't see where the ambiguity is. Isn't it obvious what we mean by
"I am X years, Y months and Z days" ?

That's obvious but given either the present date or the birth date along
with that information it's not so clear what the other date may be.
Unless you give the info about the used calender systems and the points in
time (according to which calender system!?) when to use which system.

If you are just asking those questions for people living now (and are
not called Connor McLeod ;-) and the gregorian calender it's easy but
providing functions in the standard library for arbitrary date calculation
involving years is not so easy.

Ciao,
Marc 'BlackJack' Rintsch


--
Shane Geiger
IT Director
National Council on Economic Education
(e-mail address removed) | 402-438-8958 | http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHWl4YyuP8LzpNs84RAtzmAJ4vDeb6AkiR04rkDy0iEfXuHixPrQCfYJw3
hlyZd7Z/6aiQprbbIPyB29M=
=5sXX
-----END PGP SIGNATURE-----
 
P

Pierre Quentel

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
 
G

Gabriel Genellina

En Sat, 08 Dec 2007 14:37:13 -0300, Pierre Quentel
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)

As a side note, the "legal date reckoning" in Argentina considers that
case too: 1 month after the 30th of January is Feb 28 (or 29 on leap
years); 1 month after March 31 is April 30.
 
S

StephenRFerg

You might want to look at pyfdate: http://www.ferg.org/pyfdate

This Python program:
==============================================================================
from pyfdate import *
birthday = Time(2000,2,29)

today = Time(2003,2,28)
years, months, period = today.diffym(birthday)
print "On", today.d
print "person is", years, "years", months,"months", period.shortest

today = Time(2003,3,1)
years, months, period = today.diffym(birthday)
print "On", today.d
print "person is", years, "years", months,"months", period.shortest
==============================================================================

produces this output
==============================================================================
On February 28, 2003
person is 3 years 0 months
On March 1, 2003
person is 3 years 0 months 1 day
==============================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top