Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102890

Re: problem with dateutil

From Tom P <werotizy@freent.dd>
Newsgroups comp.lang.python
Subject Re: problem with dateutil
Date 2016-02-13 21:27 +0100
Message-ID <di9ht8FtcmgU1@mid.individual.net> (permalink)
References <di995iFr285U1@mid.individual.net> <mailman.94.1455387608.22075.python-list@python.org>

Show all headers | View raw


On 02/13/2016 07:13 PM, Gary Herron wrote:
> On 02/13/2016 09:58 AM, 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?
>>
>
> Yes, there is a way to specify your own format.  Search the datetime
> documentation for
>      datetime.strptime(date_string, format)
>
> Gary Herron
>

Thanks.  I started out with datetime.strptime but AFAICS that means I 
have to go through try/except for every conceivable format. Are you 
saying that I can't use dateutil.parser?

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

problem with dateutil Tom P <werotizy@freent.dd> - 2016-02-13 18:58 +0100
  Re: problem with dateutil Gary Herron <gherron@digipen.edu> - 2016-02-13 10:13 -0800
    Re: problem with dateutil Tom P <werotizy@freent.dd> - 2016-02-13 21:27 +0100
      Re: problem with dateutil Gary Herron <gherron@digipen.edu> - 2016-02-13 12:45 -0800
        Re: problem with dateutil Tom P <werotizy@freent.dd> - 2016-02-14 13:26 +0100
  Re: problem with dateutil Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-02-13 21:01 +0000
    Re: problem with dateutil Tom P <werotizy@freent.dd> - 2016-02-14 13:27 +0100

csiph-web