Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'package,': 0.03; 'elegant': 0.07; 'string': 0.09; 'method,': 0.09; 'parsing': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:string': 0.09; 'argument,': 0.16; 'objects.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'valueerror': 0.16; 'trying': 0.19; 'header:User-Agent:1': 0.23; 'format,': 0.24; 'parse': 0.24; 'specify': 0.24; 'stick': 0.24; 'string,': 0.24; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; "i'm": 0.30; 'this.': 0.32; 'another': 0.32; 'subject:time': 0.33; "i'd": 0.34; 'could': 0.34; 'problem': 0.35; 'convert': 0.35; 'but': 0.35; 'there': 0.35; 'dates': 0.36; 'representing': 0.36; 'hi,': 0.36; 'should': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'catch': 0.60; 'full': 0.61; 'times': 0.62; 'more': 0.64; 'here': 0.66 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Wolfgang Maier Subject: converting ISO8601 date and time string representations to datetime Date: Thu, 31 Jul 2014 11:11:33 +0200 Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: bio-192-52-34-196.mobile.uni-freiburg.de User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1406797909 news.xs4all.nl 2863 [2001:888:2000:d::a6]:41031 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75407 Hi, I'm trying to convert ISO8601-compliant strings representing dates or dates and times into datetime.datetime objects. I tried using the strptime method, but the problem here is that I can only specify one format argument, which can be used to parse either a full date/time string or just a date string, but not both. While I could just try parsing with one format, then catch the ValueError in case it fails and try another format, it feels like there should be a more elegant way to do this. I do know about the dateutil package, but I'd prefer to stick to the stdlib for this. Any suggestions ? Wolfgang