Reg Date string conversion into timestamp function

Discussion in 'Python' started by praba kar, May 16, 2005.

  1. praba kar

    praba kar Guest

    Dear All,

    I have doubt regarding date string to time
    conversion function. In Python I cannot find flexible
    date string conversion function like php strtotime. I
    try to use following type
    function
    1) parsedate function failed if a date string
    like below format "16-MAY-2005 01:26"
    2)parsedate_tz function also failed if a date string
    is different format

    if any one find some other date string conversion
    function kindly let me know


    ________________________________________________________________________
    Yahoo! India Matrimony: Find your life partner online
    Go to: http://yahoo.shaadi.com/india-matrimony
    praba kar, May 16, 2005
    #1
    1. Advertising

  2. praba kar

    Mike Meyer Guest

    praba kar <> writes:

    > Dear All,
    >
    > I have doubt regarding date string to time
    > conversion function. In Python I cannot find flexible
    > date string conversion function like php strtotime. I
    > try to use following type
    > function
    > 1) parsedate function failed if a date string
    > like below format "16-MAY-2005 01:26"


    parsedate is documented as trying to parse RFC 2822 dates. Your
    example isn't one.

    > 2)parsedate_tz function also failed if a date string
    > is different format


    See the above comments for why.

    > if any one find some other date string conversion
    > function kindly let me know


    In my experience, it's not very common to have to deal with arbitrary
    time/date strings formats. Typically, a source will only provide date
    strings in one format, so you only have to be able to deal with that
    format in your application. For instance, all dates in email headers
    should follow RFC2822, which means the parsedate you found is adequate
    for any application dealing with email headers.

    Given the wide variety of date strings possible in the wild, a routine
    that swallows a such a string and produces a date is going to have to
    guess what format is being used - and there are formats that can't be
    told apart for some dates. As such, such a routine isn't very
    pythonic.

    With all that said, you can use strptime to buid a date/time
    parser. If you really need to deal with multiple formats from one
    source, maybe if you describe your application some help could be
    provided.

    <mike
    --
    Mike Meyer <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
    Mike Meyer, May 16, 2005
    #2
    1. Advertising

  3. praba kar

    Peter Hansen Guest

    praba kar wrote:
    > I have doubt regarding date string to time
    > conversion function. In Python I cannot find flexible
    > date string conversion function like php strtotime. I
    > try to use following type
    > function
    > 1) parsedate function failed if a date string
    > like below format "16-MAY-2005 01:26"
    > 2)parsedate_tz function also failed if a date string
    > is different format


    Since that's not an RFC2822 date, it shouldn't really be surprising that
    a function that is designed to parse RFC2822 dates would fail to parse
    it properly...

    Have you looked at the mxDateTime package's Parser submodule yet?
    http://www.egenix.com/files/python/mxDateTime.html#Parser

    -Peter
    Peter Hansen, May 16, 2005
    #3
  4. "praba kar" <> wrote:
    >
    > Dear All,
    >
    > I have doubt regarding date string to time
    > conversion function. In Python I cannot find flexible
    > date string conversion function like php strtotime. I
    > try to use following type
    > function
    > 1) parsedate function failed if a date string
    > like below format "16-MAY-2005 01:26"
    > 2)parsedate_tz function also failed if a date string
    > is different format
    >
    > if any one find some other date string conversion
    > function kindly let me know


    Check the other thread posted today with almost the same topic
    (http://tinyurl.com/bpcg8).

    George
    George Sakkis, May 17, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Hertz
    Replies:
    3
    Views:
    10,221
    Martin Honnen
    Oct 4, 2004
  2. praba kar
    Replies:
    1
    Views:
    395
    Max M
    Apr 8, 2005
  3. praba kar

    change the date string into timestamp

    praba kar, Apr 9, 2005, in forum: Python
    Replies:
    2
    Views:
    421
    Fabio Pliger
    Apr 9, 2005
  4. Fredrik Lundh

    Re: change the date string into timestamp

    Fredrik Lundh, Apr 9, 2005, in forum: Python
    Replies:
    0
    Views:
    373
    Fredrik Lundh
    Apr 9, 2005
  5. Dennis Oelkers
    Replies:
    2
    Views:
    206
    Dennis Oelkers
    Nov 19, 2003
Loading...

Share This Page