Re: age in years calculation

2007-08-21 Thread Brian Rosner
be born on a day that > doesn't exist. I'd recommend verifying that the data be entered into > the database is valid. > > On Aug 3, 5:37 am, Bram - Smartelectronix <[EMAIL PROTECTED]> > wrote: > > > Hey Everyone, > > > does anyone have a good

Re: age in years calculation

2007-08-21 Thread Brian Rosner
t;[EMAIL PROTECTED]> wrote: > Hey Everyone, > > does anyone have a good age in years calculation function for usage with > datetime.date that returns the age in nr of years of a person? > > We were using: > > def get_age(self): > now = datetime.today() >

Re: age in years calculation

2007-08-03 Thread Kenneth Gonsalves
On 03-Aug-07, at 10:02 PM, Nis Jørgensen wrote: >> how about surrounding the statement with a try and work the leap year >> to regular year case with the exception? > That seems like overkill. There isn't really any leap-year handling > necessary: > > import datetime.date as date this should be

Re: age in years calculation

2007-08-03 Thread Sean Perry
On Aug 3, 2007, at 9:57 AM, Doug Van Horn wrote: def age(d, bday): > ... return (d.year - bday.year) - \ > ... ((d.month, d.day) < (bday.month, bday.day) and 1 or 0) Or to be a little more explicit about it: def age(d, bday): return (d.year - bday.year) - \

Re: age in years calculation

2007-08-03 Thread Doug Van Horn
On Aug 3, 11:50 am, Doug Van Horn <[EMAIL PROTECTED]> wrote: > On Aug 3, 6:37 am, Bram - Smartelectronix <[EMAIL PROTECTED]> > wrote: [snip] You see, you learn something new every day. Based on Nis Jørgensen's post above, here's a refined age function using the fancy tuple comparison I didn't kn

Re: age in years calculation

2007-08-03 Thread Doug Van Horn
On Aug 3, 6:37 am, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: > Hey Everyone, > > does anyone have a good age in years calculation function for usage with > datetime.date that returns the age in nr of years of a person? > > We were using: > > def get_age(sel

Re: age in years calculation

2007-08-03 Thread Nis Jørgensen
Lucky B skrev: > how about surrounding the statement with a try and work the leap year > to regular year case with the exception? That seems like overkill. There isn't really any leap-year handling necessary: import datetime.date as date def age (d1, d2=None): if not d2: d2 = date.to

Re: age in years calculation

2007-08-03 Thread Lucky B
how about surrounding the statement with a try and work the leap year to regular year case with the exception? On Aug 3, 10:16 am, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: > Jonathan Buchanan wrote: > > > > > >http://toys.jacobian.org/presentations/2007/oscon/tutorial/ > > > Slide 14, u

Re: age in years calculation

2007-08-03 Thread Bram - Smartelectronix
Jonathan Buchanan wrote: > > http://toys.jacobian.org/presentations/2007/oscon/tutorial/ > > Slide 14, unit tests too! :) >>> dob = date(1980,2,29) >>> dob.replace(year=2007) Traceback (most recent call last): File "", line 1, in ValueError: day is out of range for month it ain't a part

Re: age in years calculation

2007-08-03 Thread Niels
Interesting. Would this work?? (now - birthday).days * 100 / 36524 Niels On Aug 3, 1:45 pm, "Jonathan Buchanan" <[EMAIL PROTECTED]> wrote: > On 8/3/07, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: > > > > > > > Hey Everyone, > > > do

Re: age in years calculation

2007-08-03 Thread Jonathan Buchanan
On 8/3/07, Bram - Smartelectronix <[EMAIL PROTECTED]> wrote: > > Hey Everyone, > > > does anyone have a good age in years calculation function for usage with > datetime.date that returns the age in nr of years of a person? > > We were using: > > def get_a

age in years calculation

2007-08-03 Thread Bram - Smartelectronix
Hey Everyone, does anyone have a good age in years calculation function for usage with datetime.date that returns the age in nr of years of a person? We were using: def get_age(self): now = datetime.today() birthday = datetime(now.year, self.birthday.month, self.birthday.day