Difference Between Two datetimes

Roy Smith roy at panix.com
Mon Dec 28 00:11:07 EST 2009


In article <hh9dmv$f9s$1 at news.eternal-september.org>,
 "W. eWatson" <wolftracks at invalid.com> wrote:

> 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

The first thing that jumps out at me is that %y is the two-digit year.  You 
want %Y for 4-digit year.

One thing to keep in mind is that "2009/01/02 13:01:15" is ambiguous 
without a time zone.  Even if you assume that both timestamps were from the 
same location, you need to know what daylight savings rules that location 
uses, to do this right.



More information about the Python-list mailing list