Calculating Year, Month and Day of Life

Peter Hansen peter at engcorp.com
Sat Jul 5 17:24:30 EDT 2003


hokiegal99 wrote:
> 
> Once again, I'm making progress on my own. Here's where I stand now:
> 
> ----------------------
> from time import *
> local = localtime()
> 
> y = input("Enter the year of birth: ")
> m = input("Enter the month of birth: ")
> d = input("Enter the day of birth: ")
> 
> age = y,m,d
> print "You are", local[0] - age[0], "years", local[1] - age[1], "months"
> -----------------------

Unfortunately, you won't get the right result from this in some
cases, such as when the current month is earlier in the year
than the month in which the person was born..

Using mxDateTime's support for this instead will probably be easier.




More information about the Python-list mailing list