nukeymusic <nukeymu...@gmail.com> wrote:

>I'm trying to calculate the difference in seconds between two

[...]

>>> import datetime
>>> date1 = datetime.datetime.strptime("Dec-13-09:47:12", "%b-%d-%H:%M:%S")
>>> date2 = datetime.datetime.strptime("Dec-13-09:47:39", "%b-%d-%H:%M:%S")
>>> delta = date2 - date1
>>> delta_seconds = (delta.days * 60 * 60 * 24) + delta.seconds + 
>>> ((delta.microseconds + 500000) / 1000000)

For very big time differences you should consider to use the Decimal 
arithmetics (standard module Decimal) instead of integer arithmetics 
for the last line.
If you are sure, that you don't use fractional seconds, you can omit
the part with 'delta.microseconds'.



Best regards,

Günther
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to