Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65658
| References | <CA+FnnTzV5kSJm=n0MiX6AVfnHnF4v3qq4sDT3cGnMJOxta3BZw@mail.gmail.com> <CAPTjJmqtwttJ8k2XOqoFe0QybkBQwVtw_P944y-1Cm2etqn=_A@mail.gmail.com> <CA+FnnTx0hd2zfQHy0tdO+1NzJy74PPKZWrPN8dz-Dknz2GG17Q@mail.gmail.com> |
|---|---|
| Date | 2014-02-08 01:06 -0800 |
| Subject | Fwd: datetime formatting output |
| From | Igor Korot <ikorot01@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.6532.1391850399.18130.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
---------- Forwarded message ----------
From: Igor Korot <ikorot01@gmail.com>
Date: Sat, Feb 8, 2014 at 1:06 AM
Subject: Re: datetime formatting output
To: Chris Angelico <rosuav@gmail.com>
Chris,
On Sat, Feb 8, 2014 at 12:45 AM, Chris Angelico <rosuav@gmail.com> wrote:
> On Sat, Feb 8, 2014 at 7:40 PM, Igor Korot <ikorot01@gmail.com> 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
>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Fwd: datetime formatting output Igor Korot <ikorot01@gmail.com> - 2014-02-08 01:06 -0800
csiph-web