On Nov 24, 2007, at 12:27 AM, Lawrence Shafer wrote:
How would I compare these two dates and extract the difference in H:M:S??

http://docs.python.org/lib/module-datetime.html
http://docs.python.org/lib/datetime-timedelta.html

22 Nov 2007 18:54:07
23 Nov 2007 23:24:23

>>> import datetime
>>> a = datetime.datetime(2007,11,22,18,54,7)
>>> b = datetime.datetime(2007,11,23,23,24,23)
>>> c = b - a
>>> hours = (c.seconds / (60*60))
>>> minutes = (c.seconds - (hours * 60*60)) / 60
>>> seconds = c.seconds - (hours * 60*60) - (minutes * 60)
>>> print str((c.days*24) + hours) + ":" + str(minutes) + ":" + str (seconds)
28:30:16
>>>

--
Sincerely,

Chris Calloway
http://www.seacoos.org
office: 332 Chapman Hall cell: (919) 599-3530
mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599


_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to