Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62534
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <andipersti@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'receives': 0.04; 'insert': 0.05; 'error:': 0.07; 'received:192.168.178': 0.07; 'string': 0.09; 'mysql.': 0.09; 'skip:% 20': 0.09; 'subject:string': 0.09; 'python': 0.11; 'andreas': 0.16; 'bye,': 0.16; 'csv': 0.16; 'curly': 0.16; 'format:': 0.16; 'formatted': 0.16; 'googling': 0.16; 'igor': 0.16; 'received:192.168.178.20': 0.16; 'statement.': 0.16; 'suggested,': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'bit': 0.19; 'header:User-Agent:1': 0.23; 'skip:% 10': 0.24; 'file.': 0.24; 'script': 0.25; 'transfers': 0.26; 'values': 0.27; 'header :In-Reply-To:1': 0.27; 'function': 0.29; "i'm": 0.30; 'gives': 0.31; 'file': 0.32; 'trouble': 0.34; 'could': 0.34; "can't": 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'format.': 0.36; 'doing': 0.36; 'message-id:@gmail.com': 0.38; 'follows:': 0.38; 'to:addr:python- list': 0.38; 'fact': 0.38; 'to:addr:python.org': 0.39; 'conversion': 0.61; 'field.': 0.61; 'field': 0.63; 'trial': 0.83 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=cb6JPMU+4m40D8S2Gbz9bTespp3nulWr4xQrx1DpmFU=; b=ED05wj1OH5vDRZ5S1gExCxZ+oMfYQec+wNxD66gNKbbXX+mE2Ru0AQZwwNyHUxkYnJ OrDvMZ+0+wvJFW5z4ojMKQ0xu/4vi5O3QaU8Xm8CnBK9ovf5+e+Umz/uUh021ElQMbng NLw/mm2UU6K/xsMQKomZZZP8x1fAxQTB57rNYGHigl6l8T3XBeB8SA5BMNtRpKhq7qgS oRWQUrk1HBT5z7MxjcSAXhxyU8vY6xY3yAJD7jBxtEvLSVBmN/8Sqg2WdBT1PXmnCc5j gaH6ujGUF63tSuzeFXvuZvpO4KaGmsAatxrlw3rbKYNL2aFQs80peP7PSpB6c8PDgNlJ W/uw== |
| X-Received | by 10.15.49.4 with SMTP id i4mr60899eew.116.1387731818241; Sun, 22 Dec 2013 09:03:38 -0800 (PST) |
| Date | Sun, 22 Dec 2013 18:03:35 +0100 |
| From | Andreas Perstinger <andipersti@gmail.com> |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Datetime string reformatting |
| References | <CA+FnnTyQm1V2K8c8m0NPK9TQK=WarcFGeBh1OPwpPaDsWX9V=w@mail.gmail.com> |
| In-Reply-To | <CA+FnnTyQm1V2K8c8m0NPK9TQK=WarcFGeBh1OPwpPaDsWX9V=w@mail.gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4494.1387732268.18130.python-list@python.org> (permalink) |
| Lines | 31 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1387732268 news.xs4all.nl 2874 [2001:888:2000:d::a6]:52519 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:62534 |
Show key headers only | View raw
On 22.12.2013 11:58, Igor Korot wrote:
> My script receives a data from the csv file. In this csv file there is
> a datetime field.
> This datetime field is formatted as follows: %m/%d/%Y
> %H:%M:%S.{milliseconds}. I'm reading this field into the string with
> this format.
>
> The trouble comes from the fact that I need to insert this value into
> mySQL. Doing it directly gives me an error: "Incorrect formatting".
> After a bit of googling and trial I found out that mySQL is looking
> for the format of '%Y/%m/%d %H:%M:%S.{milliseconds}.
>
> There is a mySQL function which transfers the data into the proper
> format: STR_TO_DATE(), but I can't obviously call it since it is not
> known to Python.
You don't want to call "STR_TO_DATE()" from Python but use it inside the
SQL statement.
So instead of doing the conversion in Python as Mark suggested, you
could do something like
sql_stmt = """INSERT ...
VALUES (..., STR_TO_DATE(%s, "%m/%d/%Y %H:%M:%S.{%f}"),
...)"""
cursor.execute(sql_stmt, (..., mydate_from_csv, ...))
(BTW: Do you mean microseconds instead of milliseconds? And are the
"milliseconds" really inside curly braces?)
Bye, Andreas
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Datetime string reformatting Andreas Perstinger <andipersti@gmail.com> - 2013-12-22 18:03 +0100
csiph-web