Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'static': 0.04; 'string.': 0.05; 'differently': 0.07; 'mysql,': 0.07; 'table.': 0.07; 'string': 0.09; 'locale': 0.09; 'subject:How': 0.10; 'python': 0.11; 'csv': 0.16; 'fields:': 0.16; 'formatted': 0.16; 'inserting': 0.16; 'all,': 0.19; 'trying': 0.19; 'file.': 0.24; 'looks': 0.24; 'question': 0.24; 'script': 0.25; 'tried': 0.27; 'function': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'file': 0.32; 'subject:the': 0.34; 'convert': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'consist': 0.36; 'dates': 0.36; 'i.e.': 0.36; 'object,': 0.36; "didn't": 0.36; 'subject:?': 0.36; 'hi,': 0.36; 'so,': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'according': 0.40; 'how': 0.40; 'simple': 0.61; 'kind': 0.63; 'field': 0.63; 'different': 0.65; 'date,': 0.68; 'generated.': 0.68; 'reads': 0.68; 'sole': 0.78; 'subject:check': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=RDgLJ5LIzqpe4n36gwPbAADiRZO9WTReFUx3otyVqpA=; b=enuCp9UAULMm89wGGk9j/VC1KWnGYS2qGK1o4RpryFZD0ELpnY2VC9zeySC0lE0K9Y 6x4iwk7y9ixRb3IFQyY1nUZBbmBL67JrduOjVfG76lkO09rBdeSaW7w7Sb85E3EBgZ9p zx3Mwo2tGfjqdNrH06McJUV8GkbSdh1R3IzIMMvvou/z+KGrdbud8gFk0H7/zFUbCAVm WnJT4xsEahIqSQVfmpEKhOfMjusED0cb+FaoJXr8LtSuSXy78ZPRSb/CCjygWhbXNGAF NluVtUflkedEeFgRdjgct8SBgKmluBFSoUr4lGWXD++68CVRfo1RpdSjIlJicrcgDrF5 2UzA== MIME-Version: 1.0 X-Received: by 10.182.88.4 with SMTP id bc4mr81165obb.68.1387845035271; Mon, 23 Dec 2013 16:30:35 -0800 (PST) Date: Mon, 23 Dec 2013 16:30:35 -0800 Subject: How to check the date validity? From: Igor Korot To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1387845038 news.xs4all.nl 2848 [2001:888:2000:d::a6]:57085 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:62658 Hi, ALL, I'm working on the python script which reads the data from the csv file. In this file I have 3 different kind of fields: one consist of the sole date, one - sole time and one - datetime. The time includes milliseconds, i.e. "12:55:55.705" All fields of the file including those 3 I am reading as the string. All those strings after validating will go into mySQL table. Now, it looks that the python way of validating the date/time of the string is to call strptime(). However looking at the docs and trying to use the function I didn't find a way to check for the milliseconds. Now the dates can be formatted differently I think according to the locale under which the csv is generated. 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? I don't want to convert that string to datetime object, just want to check if all those types of dates are good dates and does not contain garbage. I tried to do an RE, but its static validation and so will not work in all cases. Thank you for any hints.