dateutil timezone question

Chris Angelico rosuav at
Fri Dec 23 14:18:46 EST 2016

On Sat, Dec 24, 2016 at 3:30 AM, Larry Martell <larry.martell at> wrote:
> I have a datetime that looks like this: '2016-11-11T18:10:09-05:00'
> and when I pass it to dateutil.parser.parse I get back this:
> datetime.datetime(2016, 11, 11, 18, 10, 9, tzinfo=tzoffset(None, -18000))
> And I have other datetimes like this: '2016-04-27T00:00:00', which
> went passed to dateutil.parser.parse of course does not return a
> datetime with the tzinfo.
> I need to compare these datetimes, and if I do that I get the dreaded
> "can't compare offset-naive and offset-aware datetimes" error.

Some of your timestamps have timezones and others don't. That's a
fundamental problem. Are you absolutely certain that the ones without
them are in UTC? If so, the easiest fix would be to slap a "Z" on them
before you parse, which would give you exclusively aware datetimes.


More information about the Python-list mailing list