Difference Between Two datetimes

W. eWatson wolftracks at invalid.com
Sun Dec 27 23:54:57 EST 2009


According to one web source, this program:

import datetime
bree = datetime.datetime(1981, 6, 16, 4, 35, 25)
nat  = datetime.datetime(1973, 1, 18, 3, 45, 50)

difference = bree - nat
print "There were", difference, "minutes between Nat and Bree"

yields:
There were 3071 days, 0:49:35 minutes between Nat and Bree

That's fine, but I'd like to start with two dates as strings, as
"1961/06/16 04:35:25" and "1973/01/18 03:45:50"

How do I get the strings into a shape that will accommodate a difference?

For example,
t1=datetime.datetime.strptime("2009/01/02 13:01:15","%y/%m/%d %H:%M:%S")
doesn't do it.
ValueError: time data did not match format:  data=2009/01/02 13:01:15 
fmt=%y/%m/%d %H:%M:%S



More information about the Python-list mailing list