date diff calc

tertius terti at mighty.co.za
Mon Nov 29 10:16:24 EST 2004


Hi,

Is there a more pythonic way to write or do a date difference 
calculation? I have as input two date fields in the form 'YYYY-MM-DD'

TIA
Terius



from datetime import date

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]))

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



More information about the Python-list mailing list