Parsing a date-time string?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim N. van der Leeuw

    #1

    Parsing a date-time string?

    Hi,

    I want to parse strings containing date-time, which look like the
    following:

    "Mon Dec 19 11:06:12:333 CET 2005"

    That's a problem for strptime it seems, b/c I cannot find any
    format-spec for the milliseconds-part in here. (I'm also not sure about
    the validity of the tz part, but ...)

    As an aside, the dates are all in english while my PC might have a
    dutch locale -- not even sure about what Python would consider the
    current locale.
    So that's an extra obstacle to parsing these dates.

    The datetime module doesn't seem to provide a better solution either.

    What I want to get is some sort of sortable date; either as a number or
    (if nothing else) as a string in ISO8601 format.
    (But I want to avoid doing too many string manipulations on my input
    dates; and changing the dateformat of the input-source will be hard if
    at all justifiable.)


    Any help is appreciated.

    Cheers,

    --Tim

  • Fuzzyman

    #2
    Re: Parsing a date-time string?

    Quick response - there is a DateUtil module with a *very* flexible
    string-to-date parser. It will almost certainly do what you want :



    All the best,

    Fuzzyman
    http://www.voidspace.org.uk/python/index.shtml

    Comment

    • linda.s

      #3
      Re: Parsing a date-time string?

      Hi Fuzzyman,
      I also wanted to install the DateUtil module from

      but had problems (using Windows).
      C:\Python24>pyt hon python-dateutil-1.0\setup.py build
      running build
      running build_py
      error: package directory 'dateutil' does not exist
      Can you tell me why?
      Linda

      On 21 Dec 2005 01:53:49 -0800, Fuzzyman <fuzzyman@gmail .com> wrote:[color=blue]
      > Quick response - there is a DateUtil module with a *very* flexible
      > string-to-date parser. It will almost certainly do what you want :
      >
      > http://labix.org/python-dateutil
      >
      > All the best,
      >
      > Fuzzyman
      > http://www.voidspace.org.uk/python/index.shtml
      >
      > --
      > http://mail.python.org/mailman/listinfo/python-list
      >[/color]

      Comment

      • linda.s

        #4
        Re: Parsing a date-time string?

        I did check and found 'dateutil' is under
        the folder of python-dateutil-1.0
        very confused, :(

        On 12/21/05, linda.s <samrobertsmith @gmail.com> wrote:[color=blue]
        > Hi Fuzzyman,
        > I also wanted to install the DateUtil module from
        > http://labix.org/python-dateutil
        > but had problems (using Windows).
        > C:\Python24>pyt hon python-dateutil-1.0\setup.py build
        > running build
        > running build_py
        > error: package directory 'dateutil' does not exist
        > Can you tell me why?
        > Linda
        >
        > On 21 Dec 2005 01:53:49 -0800, Fuzzyman <fuzzyman@gmail .com> wrote:[color=green]
        > > Quick response - there is a DateUtil module with a *very* flexible
        > > string-to-date parser. It will almost certainly do what you want :
        > >
        > > http://labix.org/python-dateutil
        > >
        > > All the best,
        > >
        > > Fuzzyman
        > > http://www.voidspace.org.uk/python/index.shtml
        > >
        > > --
        > > http://mail.python.org/mailman/listinfo/python-list
        > >[/color]
        >[/color]

        Comment

        • Tim N. van der Leeuw

          #5
          Re: Parsing a date-time string?

          I downloaded the tar.bz2 file, extracted it, and had no problem
          building it and creating a windows installer using 'python ./setup.py
          bdist_wininst'

          This windows installer I then used to install it via the 'official
          windows' way :)

          luck,

          --Tim

          Comment

          • Tim Roberts

            #6
            Re: Parsing a date-time string?

            "Tim N. van der Leeuw" <tim.leeuwvande r@nl.unisys.com > wrote:[color=blue]
            >
            >I want to parse strings containing date-time, which look like the
            >following:
            >
            > "Mon Dec 19 11:06:12:333 CET 2005"
            >
            >That's a problem for strptime it seems, b/c I cannot find any
            >format-spec for the milliseconds-part in here. (I'm also not sure about
            >the validity of the tz part, but ...)[/color]

            Central European Time. GMT +1 hour. Quite valid.
            --
            - Tim Roberts, timr@probo.com
            Providenza & Boekelheide, Inc.

            Comment

            • linda.s

              #7
              Re: Parsing a date-time string?

              Hi,
              I got the message of "There was an error in the DDE conversation with
              Pythonwin" when I tried to run Pythonwin.
              I googled and found the possible solution is:
              modify the Pythonwin shortcut to pass a
              "/nodde" command-line option.
              I got lost how to do that.
              Thanks for any help!

              Comment

              Working...