datetime iso8601 string input



I was a little surprised to recently discover
that datetime has no method to input a string
value. PEP 321 appears does not convey much
information, but a timbot post from a couple
years ago clarifies things:

http://tinyurl.com/epjqc

You can stop looking: datetime doesn't
support any kind of conversion from string.
The number of bottomless pits in any datetime
module is unbounded, and Guido declared this
particular pit out-of-bounds at the start so
that there was a fighting chance to get
*anything* done for 2.3.

I can understand why datetime can't handle
arbitrary string inputs, but why not just
simple iso8601 format -- i.e. the default
output format for datetime?

Given a datetime-generated string:

>>> now = str(datetime.datetime.now())
>>> print now
'2006-02-23 11:03:36.762172'

Why can't we have a function to accept it
as string input and return a datetime object?

datetime.parse_iso8601(now)

Jeff Bauer
Rubicon, Inc.

.



Relevant Pages

  • Re: Dates
    ... The conversion of a char data type to a datetime data type resulted in an ... out-of-range datetime value. ... System.Data.Common.DbDataAdapter.FillFromReader(Object data, String ... srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: DateTime WebService Discrepancy.
    ... When the datetime is sent by the webservice, ... > Ofcourse I had not even though of just passing a string as a parameter ... > locally and cut out the call to the web service. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Axis <-> .Net xsd:date interoperability problem
    ... .NET can de-serialize from alternative string representations of the date, ... but you need to tell it the format to expect. ... DateTime to be set. ... serialization of all DateTime's. ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Zeitzonen und Benutzerdefinierte Formate --- Problem
    ... "Die Zeichenfolge wurde nicht als gültiges DateTime erkannt." ... Public Function ConvertDateTimeToCulture(ByVal sDateTime As String, ... Dim InputCulture = New ... Thread.CurrentThread.CurrentCulture = InputCulture ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • the safest way of handling datetime between asp.net and ms sql
    ... I know that a problem of different datetime strings formatting between ... asp.net and ms sql has been covered here widely, ... Let's say I'm keeping datetime variable in a session. ... cast it - how can I prevent it from casting it to string and inserting ...
    (microsoft.public.dotnet.framework.aspnet)