date diff calc

Diez B. Roggisch deetsNOSPAM at web.de
Mon Nov 29 13:28:29 EST 2004


> bdl = '2004-11-25'.split('-')
> edl = '2004-11-30'.split('-')
> bd = date(int(bdl[0]),  int(bdl[1]),  int(bdl[2]))
> ed = date(int(edl[0]),  int(edl[1]),  int(edl[2]))

using time.strptime and datetime.date.fromtimestamp is surely the better
alternative, as it lets specify you the format by a string.

> print ed , '-', bd , '=', (ed-bd).days

I can't imagine what could possibly be easier than subtracting two dates -
in fact, most times one has to jump through much more hoops to achieve
these results, e.g. in java.

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list