Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'broken': 0.04; 'mysql,': 0.07; 'string': 0.09; 'postgresql,': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; '24,': 0.16; 'docs.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'igor': 0.16; 'inserting': 0.16; 'valid.': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'cc:addr:python.org': 0.22; 'question': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; 'subject:the': 0.34; 'transaction': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'subject:?': 0.36; 'so,': 0.37; 'being': 0.38; 'easiest': 0.38; 'how': 0.40; 'simply': 0.61; 'simple': 0.61; 'back': 0.62; 'field': 0.63; 'protect': 0.79; 'different.': 0.84; 'subject:check': 0.84; 'to:none': 0.92; '2013': 0.98 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:cc :content-type; bh=/WWRyVK+j1mVpj5k1N4PdSq4Ej2kFJ1Pa1H01XBgWEI=; b=nmI05OceJMmQ6/OBfw93PU0LNiGH52BWBNN6GESEDUIsjaaEojHVoT77lpDKOvHJFT xCJrTNE3tLDuVCjGpznBPUnQ6I+deqQI4wGq54cLxoOOxiqoGMvvsSQ8FiNwC7cXtrQx CH55LTstllZjnUDKGz+Zc8QpV+sFd3oo0IV9AX2zbKzOymdhdtY+DBifoERJ1sbAie3v oN7DlPjbrZdzUBduIG+lz+nDNHWTeev9vna1LJF7nmJ8+kUlN4bw+tVPmtHln1kpZeTr W0NQNkteq65kdudwQeSadozQ80jJXwViRYYy7fQKTRWg5Br6agyJTtQHlFmwX5D1IxWx Q6cg== MIME-Version: 1.0 X-Received: by 10.66.164.136 with SMTP id yq8mr29365874pab.67.1387845564189; Mon, 23 Dec 2013 16:39:24 -0800 (PST) In-Reply-To: References: Date: Tue, 24 Dec 2013 11:39:24 +1100 Subject: Re: How to check the date validity? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 13 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1387845567 news.xs4all.nl 2936 [2001:888:2000:d::a6]:34178 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:62660 On Tue, Dec 24, 2013 at 11:30 AM, Igor Korot wrote: > So, my question is: since there is a simple way of inserting > preformatted string into the datetime field of mySQL, how do I > validate the date string? Well, the easiest way would be to simply attempt the SQL query. If it comes back with an error, the date wasn't valid. To protect a transaction against being broken by an error, you can use a SAVEPOINT - check the database docs. (I've never actually used savepoints in MySQL, only PostgreSQL, so things may be a bit different. Check the docs.) ChrisA