Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!news2.euro.net!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; 'except:': 0.07; 'try:': 0.07; 'subject:skip:a 10': 0.09; 'truncate': 0.09; 'itself.': 0.11; "'%d": 0.16; 'received:your-server.de': 0.16; 'sys.exit(0)': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'feb': 0.19; 'trying': 0.21; 'import': 0.21; 'of.': 0.22; 'skip:= 20': 0.22; 'work.': 0.23; 'this:': 0.23; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'charset:iso-8859-15': 0.26; '+0100,': 0.29; 'this.': 0.29; 'fri,': 0.30; 'month,': 0.33; 'to:addr:python-list': 0.33; 'skip:d 20': 0.34; 'anything': 0.36; 'being': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'think': 0.40; 'day,': 0.60; 'spending': 0.61; 'hours': 0.66; '2013': 0.84; 'break.': 0.84 Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes To: python-list@python.org Subject: Re: Checking for valid date input and convert appropriately References: <92536c34-cf00-4497-b646-ab79fa4ee062@googlegroups.com> <5bac38bb-df2e-47b8-96dd-2b1c090959e4@googlegroups.com> <49de0696-b6f6-42ce-9272-79dac37c9605@googlegroups.com> Date: Fri, 22 Feb 2013 01:57:03 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: "Michael Ross" In-Reply-To: <49de0696-b6f6-42ce-9272-79dac37c9605@googlegroups.com> User-Agent: Opera Mail/12.14 (Win32) X-Authenticated-Sender: gmx@ross.cx X-Virus-Scanned: Clear (ClamAV 0.97.5/16717/Fri Feb 22 00:38:42 2013) 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: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361494634 news.xs4all.nl 6919 [2001:888:2000:d::a6]:54482 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39510 On Fri, 22 Feb 2013 01:12:40 +0100, Ferrous Cranus wrote: > Please i have been trying hours for this: Don't do that: Spending hours on being stuck. Take a break. Call it a night. Brain needs time to unstick itself. Besides: >>> from datetime import date >>> entry='31 03 2013' >>> day, month, year = int(entry[:2]), int(entry[3:5]), int(entry[6:]) >>> mydate=date(year,month,day) >>> mydate.strftime('%Y-%m-%d') '2013-03-31' > try: > datetime.strptime(date, '%d m% %Y') > date = date.strftime('%Y-%m-%d') > except: > print( "

date not propetly entered." ) > sys.exit(0) > =========================== > > the user enters 21 02 2013 > > a) i just need to check if its in accepted format > b) then truncate the given date to mysql format > > That's all i want to do and i cant make it work. Plese tell me how to > write this. > > I have tried anything i can think of.