[Tutor] timedelta, difference calculation

rail shafigulin rail.shafigulin at gmail.com
Mon Dec 12 20:46:40 CET 2011


i found something interesting during the timedate difference calculation

import datetime
import time

def main():
  mydatetime = datetime.datetime.now()
  time.sleep(1)
  mydatetime2 = datetime.datetime.now()
  diff = mydatetime - mydatetime2

  print(diff)

if __name__ == '__main__':
  main()

if you run this code the result you get will be
-1 day, 23:59:59

at least that is what i'm getting.

i was expecting to get -1 second. diff object is of type timedelta. this
kind of objects represent duration, at least that is what i understood from
the documentation (
http://docs.python.org/release/3.1.3/library/datetime.html#timedelta-objects).
so, is this a bug in the timedelta implementation or is it me not
understanding documentation properly?

any help is appreciated.

ps. i'm using python 3.1 on a windows xp machine.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111212/adbb16f1/attachment.html>


More information about the Tutor mailing list