Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; ';-)': 0.03; 'output': 0.05; 'none:': 0.07; 'debugger': 0.09; 'formatting': 0.09; 'objects,': 0.09; 'stored': 0.12; '23,': 0.16; 'chris,': 0.16; 'igor': 0.16; 'sat,': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'module': 0.19; 'help.': 0.21; 'feb': 0.22; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'putting': 0.22; '\xa0if': 0.24; 'question': 0.24; '>': 0.26; 'possibly': 0.26; '----------': 0.26; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'field,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'getting': 0.31; 'url:python': 0.33; 'date:': 0.34; 'maybe': 0.34; 'problem': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'shows': 0.36; 'url:org': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'previous': 0.38; 'forwarded': 0.39; 'subject:': 0.39; '12,': 0.39; 'generating': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'field.': 0.61; 'subject:Fwd': 0.61; "you're": 0.61; 'show': 0.63; 're:': 0.63; 'real': 0.63; 'field': 0.63; 'as:': 0.81; 'milliseconds': 0.84; 'p.s.:': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ZOiwv+HUjeypiYcNeTCvDWztxHsR/lhWDSEA0aOxAV0=; b=U9NM+ldEuDz0NrOIvZTNy512EZn3AEiWnKyFuHWUGl3AaPcf7u7mVdDq/e/o+VIjcp vgI+S+FcAwEib8votdVBBPxOl4ViDwNjvbGaXsJ3vYHuCsb0krngLi08abp8Q2Qdx5Fr 8jo1OtcP/vyYlwIj9pRyjYCOlOYBfOfonKAoGYnNO7TU4dP/cCnxK8+bhJNvI3xWHz63 RowTSMdpbBHxBkGI303jELTh9KP60+myecftUDYHRLtLe5GaabeI0F3gIb1onXAh3QNh nNMKmmu0tswLrQaStaukoyuLAFPLUZL60esDkFerE93fhUELfJIK1ZCdtEhaP54gAnJv fLwQ== MIME-Version: 1.0 X-Received: by 10.52.247.231 with SMTP id yh7mr13755vdc.34.1391850391001; Sat, 08 Feb 2014 01:06:31 -0800 (PST) In-Reply-To: References: Date: Sat, 8 Feb 2014 01:06:30 -0800 Subject: Fwd: datetime formatting output From: Igor Korot To: python-list@python.org Content-Type: multipart/alternative; boundary=001a1133c9aa22df7b04f1e16c65 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 131 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391850399 news.xs4all.nl 2978 [2001:888:2000:d::a6]:35616 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65658 --001a1133c9aa22df7b04f1e16c65 Content-Type: text/plain; charset=ISO-8859-1 ---------- 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 > --001a1133c9aa22df7b04f1e16c65 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable


---------- Forwarded me= ssage ----------
From: Igor Korot <ikorot01@gmail.com<= /a>>
Date: Sat, Feb 8, 2014 at 1:06 AM
Subject: Re: datetime formatting outpu= t
To: Chris Angelico <
rosuav@gmai= l.com>


Chris,
=

On Sat, Feb 8, 2014 a= t 12:45 AM, Chris Angelico <rosuav@gmail.com> wrote:
On Sat, Feb 8, 2014 at 7:40 PM, Igor Ko= rot <ikorot01@gm= ail.com> wrote:
> I am reading data from the DB (mySQL) where the datetime field is stor= ed as:
>
> 2012-12-12 23:59:59.099
>
> When I retrieve this date I am successfully see under debugger the dat= eteime
> object with (2012, 12, 12, 23, 59, 59, 099)
>
> However as you can see from my previous post this date shows up incorr= ectly
> 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 questio= n 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 My= SQLdb as mdb
self.conn =3D mdb.connect()
self.cur =3D s= elf.conn.cursor()
self.cur.execute("SELECT * FROM mytable")
db_resul= ts =3D self.cur.fetchall()
for row in db_results:
=A0 = =A0 =A0my_dict =3D {}
=A0 =A0 =A0#Fill in my_dict
=A0 = =A0 =A0if row[3] is not None:
=A0 =A0 =A0 =A0 =A0 my_dict["Install"] =3D row[3]
=
That's all.

P.S.: Maybe its a p= roblem with the datetime module which formats the datetime incorrectly?


ChrisA
--
https://mail.python.org/mailman/listinfo/python-list


--001a1133c9aa22df7b04f1e16c65--