[Tutor] Date comparison across time zones

frenc1z 1z frenc1z at gmail.com
Tue Jan 13 17:45:38 CET 2009


Hello,

I'm a novice python (python 2.6.1) user with the following problem.

Never though this was going to be so difficult :-).

I would like to compare some dates (date+time really). The dates all have
the following RFC2822 format:

Eg. is d1 < d2?
d1 = "Tue, 13 Jan 2009 03:27:29 -0800"
d2 = "Tue, 13 Jan 2009 02:40:00 -0600"

My thinking is that I first need to make these two dates comparable, and
eliminate the impact of time zone and dst. Understand that I can acheive
this using strptime.

Been trying to parse these dates as follows: print datetime.strptime("Tue,
13 Jan 2009 02:40:00 -0800", "%a, %d %b %Y %H:%M:%S %z").

I get the following error on the conversion "ValueError: 'z' is a bad
directive in format '%a, %d %b %Y %H:%M:%S %z'".

>From what I have read, I understand that python 2.6 would support the %z
directive, so I do not really understand the error.

Apart from that, how can I best attach this problem? At first sight it would
seem trivial, but unfortunately I can't build on sufficient experience in
python to get to a solution.

Many thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090113/d8c56a3d/attachment.htm>


More information about the Tutor mailing list