Caculate age
Alex Martelli
aleax at aleax.it
Tue Feb 4 04:21:35 EST 2003
Ben Patel wrote:
...
> # Enter any birthdate in the format MM/DD/YYYY or MM-DD-YYYY
> # Uses mx.DateTime interface from www.lemburg.com
...
> How can I make it accept any format (YYYY-MM-DD etc..)
Then use DateFrom -- it does a HEROIC job of guessing:
>>> mx.DateTime.DateFrom('2000-11-23')
<DateTime object for '2000-11-23 00:00:00.00' at 8133d78>
>>> mx.DateTime.DateFrom('11/23/2000')
<DateTime object for '2000-11-23 00:00:00.00' at 818d908>
>>>
> from mx.DateTime import *
Don't do this. If you forget the existence of statement
"from" altogether, and always only use statement "import",
it's likely that, on balance, your Python code will become
of better quality. In particular, forget the "import *"
thingy, and live happily ever after.
Alex
More information about the Python-list
mailing list