[egenix-users] Re: Struggling to read a simple date text format

eGenix Support: M.-A. Lemburg support at egenix.com
Sat Jul 15 11:59:59 CEST 2006


[Please post such questions to egenix-users, so that others can benefit
 from the answers as well]

Simon Hook wrote:
> Hi,
> 
> I have been trying to use DateTime but keep having problems with what I
> think is a fairly standard format:
> 
> "2005-05-05 10:10:10.00"
> or
> YYYY-MO-DD HH:MM:SS.ss
> 
> its the fractional seconds that cause the problems.  Below are some
> examples that work and some that do not (examples "c" and "d", examples
> that fail are commented out). Any idea how to get "c" and "d" to work? I
> think "c" should work and there has to be some literal to tell strptime
> to ignore a character but I cannot find it.
> 
> Many thanks,
> 
> Simon
> 
> ------
> 
> from time import *
> from mx.DateTime import *
> 
> a=ISO.ParseDateTimeUTC("2005-05-05 10:10:10.00")
> print a
> 
> b=Parser.DateTimeFromString("2005-05-05 10:10:10.00")
> print b
> 
> # This fails
> #c=Parser.DateTimeFromString("2005-05-05 10:10:10.00",'iso')
> #print c

This should read:

>>> c=Parser.DateTimeFromString("2005-05-05 10:10:10.00",('iso',))
>>> print c
2005-05-05 10:10:10.00

> # This fails
> # d=strptime("2005-05-05 10:10:10.00","%Y-%m-%d %H:%M:%S")
> # print d

This doesn't work, since the strptime %S parser doesn't support
fractions, mainly because the structure which strptime
returns uses integers for the seconds part.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jul 15 2006)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::



More information about the egenix-users mailing list