Fwd: datetime formatting output

Discussion in 'Python' started by Igor Korot, Feb 8, 2014.

  1. Igor Korot

    Igor Korot Guest

    ---------- Forwarded message ----------
    From: Igor Korot <>
    Date: Sat, Feb 8, 2014 at 1:06 AM
    Subject: Re: datetime formatting output
    To: Chris Angelico <>


    Chris,


    On Sat, Feb 8, 2014 at 12:45 AM, Chris Angelico <> wrote:

    > On Sat, Feb 8, 2014 at 7:40 PM, Igor Korot <> wrote:
    > > I am reading data from the DB (mySQL) where the datetime field is stored

    > as:
    > >
    > > 2012-12-12 23:59:59.099
    > >
    > > When I retrieve this date I am successfully see under debugger the

    > dateteime
    > > object with (2012, 12, 12, 23, 59, 59, 099)
    > >
    > > However as you can see from my previous post this date shows up

    > incorrectly
    > > as:
    > >
    > > 2012-12-12 23:59:59.000099
    > >
    > > Notice 3 extra 0's in the milliseconds field.

    >
    > It's not a milliseconds field, that's why :) The real question is: Why
    > is the datetime you're getting from MySQL putting milliseconds into
    > the microseconds field? Possibly if you show your code for generating
    > those datetime objects, that would help.
    >


    Nothing fancy, really. ;-)

    import MySQLdb as mdb
    self.conn = mdb.connect()
    self.cur = self.conn.cursor()
    self.cur.execute("SELECT * FROM mytable")
    db_results = self.cur.fetchall()
    for row in db_results:
    my_dict = {}
    #Fill in my_dict
    if row[3] is not None:
    my_dict["Install"] = row[3]

    That's all.

    P.S.: Maybe its a problem with the datetime module which formats the
    datetime incorrectly?


    > ChrisA
    > --
    > https://mail.python.org/mailman/listinfo/python-list
    >
     
    Igor Korot, Feb 8, 2014
    #1
    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. Davide Carboni
    Replies:
    0
    Views:
    364
    Davide Carboni
    Dec 18, 2003
  2. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    719
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  3. Tim Peters
    Replies:
    0
    Views:
    544
    Tim Peters
    Sep 9, 2003
  4. mp
    Replies:
    1
    Views:
    397
    John Machin
    Jul 28, 2006
  5. Martin
    Replies:
    0
    Views:
    342
    Martin
    Dec 27, 2008
Loading...

Share This Page