converting time tuple to datetime struct

Discussion in 'Python' started by Michael Jard, Mar 3, 2005.

  1. Michael Jard

    Michael Jard Guest

    there a shorter way then:
    datetime.fromtimestamp(time.mktime(time.strptime("20-3-2005","%d-%b-%y")))

    thanks,
    Mike
    Michael Jard, Mar 3, 2005
    #1
    1. Advertising

  2. Michael Jard

    Guest

    [your "%b" is supposed to be the abbreviated month name, not the
    number. Try "%m"]

    In [19]: datetime.datetime(*time.strptime("20-3-2005","%d-%m-%Y")[:6])
    Out[19]: datetime.datetime(2005, 3, 20, 0, 0)

    Cheers,
    George
    , Mar 3, 2005
    #2
    1. Advertising

  3. Michael Jard

    Michael Jard Guest

    Yeah, that was just an oversight while retyping the code. Thanks from
    the prompt reply, it was just what I needed.

    Mike
    Michael Jard, Mar 3, 2005
    #3
    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. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    690
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    523
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    377
    John Machin
    Jul 28, 2006
  4. Martin
    Replies:
    0
    Views:
    328
    Martin
    Dec 27, 2008
  5. Stuart
    Replies:
    6
    Views:
    205
    Seungbeom Kim
    Mar 11, 2013
Loading...

Share This Page