Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Mark Lawrence Newsgroups: comp.lang.python Subject: Re: problem with dateutil Date: Sat, 13 Feb 2016 21:01:01 +0000 Lines: 37 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 0wW/y3PeltDvUp2wEdkU9wSkpt2FyLvAV8cBPj5Xn9Qg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.05; 'tom': 0.07; '22,': 0.09; 'format?': 0.09; 'instance.': 0.09; 'may,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'ignore': 0.14; 'skip:p 40': 0.15; 'colons': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'result:': 0.16; 'wrote:': 0.16; 'string': 0.17; 'language': 0.19; 'lawrence': 0.22; 'parameter': 0.22; 'parser': 0.22; 'subject:problem': 0.22; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; 'separate': 0.27; 'format,': 0.27; 'looks': 0.29; '13,': 0.29; 'strings,': 0.29; 'convert': 0.29; 'allows': 0.30; 'language.': 0.32; 'getting': 0.33; 'class': 0.33; 'handle': 0.34; 'skip:d 20': 0.34; 'formats': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'url:org': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'wrong': 0.38; 'to:addr:python.org': 0.40; 'mark': 0.40; 'subject:with': 0.40; 'charset:windows-1252': 0.62; 'different': 0.63; 'our': 0.64; 'pythonistas,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: 80.234.182.166 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21rc2 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:102892 On 13/02/2016 17:58, Tom P wrote: > I am writing a program that has to deal with various date/time formats > and convert these into timestamps. It looks as if dateutil.parser.parse > should be able to handle about any format, but what I get is: > > datetimestr = '2012-10-22 11:22:33' > print(dateutil.parser.parse(datetimestr)) > result: datetime.datetime(2012, 10, 22, 11, 22, 33) > > However: > datetimestr = '2012:10:22 11:22:33' > print(dateutil.parser.parse(datetimestr)) > result: datetime.datetime(2016, 2, 13, 11, 22, 33) > > In other words, it's getting the date wrong when colons are used to > separate YYYY:MM:DD. Is there a way to include this as a valid format? > From http://labix.org/python-dateutil#head-a23e8ae0a661d77b89dfb3476f85b26f0b30349c parserinfo This parameter allows one to change how the string is parsed, by using a different parserinfo class instance. Using it you may, for example, intenationalize the parser strings, or make it ignore additional words. HTH. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence