[Python] Ma quanto sono vecchio? (Gestione date)

Simone Federici s.federici a gmail.com
Mar 14 Apr 2015 15:48:39 CEST


Gabriele Battaglia:

> Mi risponde: 41, 7, 31.


from datetime import *
from calendar import monthrange

born = date(1974,9,13)
today = date.today()

age = today.year - born.year - ((today.month, today.day) < (born.month,
born.day)), (today.month - born.month + - (today.day<born.day)) % 12,
today.day-born.day + (0 if today.day>=born.day else monthrange(born.year,
born.month)[1])

# (40, 7, 1)
-------------- parte successiva --------------
Un allegato HTML è stato rimosso...
URL: <http://lists.python.it/pipermail/python/attachments/20150414/e3fdbfb3/attachment.html>


Maggiori informazioni sulla lista Python