Difference Between Two datetimes

W. eWatson wolftracks at invalid.com
Mon Dec 28 06:41:28 EST 2009


Lie Ryan wrote:
> On 12/28/2009 5:42 PM, W. eWatson wrote:
>> You're right. Y. Works fine. The produces datetime.datetime(2009, 1, 2,
>> 13, 1, 15).
>> If I now use
>> t2=datetime.datetime.strptime("2009/01/04 13:01:15","%Y/%m/%d %H:%M:%S")
>> I get tw as
>> datetime.datetime(2009, 1, 4, 13, 1, 15)
>> Then t2-t1 gives,
>> datetime.timedelta(2)
>> which is a 2 day difference--I guess. Strange.
> 
> what's strange about it? the difference between 2009/01/02 13:01:15 and 
> 2009/01/04 13:01:15 is indeed 2 days... Can you elaborate what do you 
> mean by 'strange'?
Easily. In one case, it produces a one argument funcion, and the other 
2, possibly even a year if that differs. How does one "unload" this 
structure to get the seconds and days?
> 
>> Changing
>> t2=datetime.datetime.strptime("2009/01/04 14:00:30","%Y/%m/%d %H:%M:%S")
>> and differencing gives me,
>> datetime.timedelta(2, 3555), which seems to indicate a 2 day and 3555
>> second difference. Interesting, but I think there must be another way to
>> do this. Maybe not.
> 
> to do... what?
To find the difference more clearly. Why not just return (0,2,3555)



More information about the Python-list mailing list