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,
>
> > 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)
> >     return now.year - self.birthday.year - (birthday > now)
>
> > But the trouble is that this fails for people whose birthday falls on a
> > leap-day! ( bday = 1980-02-29 => birthday this year doesn't exist :-) )
>
> > For now I swaped to:
>
> > try:
> >   birthday = datetime(now.year, self.birthday.month, self.birthday.day)
> > except ValueError:
> >   birthday = datetime(now.year, self.birthday.month, self.birthday.day-1)
>
> > But that seems such a hack :-))
>
> >   - bram
>
> http://toys.jacobian.org/presentations/2007/oscon/tutorial/
>
> Slide 14, unit tests too! :)
>
> Jonathan.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to