[Python] Ma quanto sono vecchio? (Gestione date)
Gabriele Battaglia
iz4apu a libero.it
Mar 14 Apr 2015 16:15:53 CEST
Simone Federici, alle 15:48 del 14/04/2015, digiṭ:
> 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)
:) Grazie per avermi restituito la mia giovinezza!GB.
Maggiori informazioni sulla lista
Python