Difference Between Two datetimes

Lie Ryan lie.1296 at gmail.com
Mon Dec 28 02:14:48 EST 2009


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'?

> 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?



More information about the Python-list mailing list