Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'method.': 0.05; 'mrab': 0.05; 'thats': 0.07; 'try:': 0.07; 'be:': 0.09; 'object;': 0.09; 'parsed': 0.09; 'subject:skip:a 10': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'result.': 0.15; "%y'": 0.16; "'%d": 0.16; 'wrote:': 0.17; 'string,': 0.17; 'import': 0.21; 'thanks.': 0.21; 'defined': 0.22; 'cc:2**0': 0.23; 'task': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; "doesn't": 0.28; 'crash': 0.29; 'convert': 0.29; 'this.': 0.29; 'correctly.': 0.33; 'skip:d 20': 0.34; 'received:google.com': 0.34; 'entered': 0.34; 'wrong': 0.34; 'received:209.85': 0.35; 'but': 0.36; 'should': 0.36; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'store': 0.38; 'sure': 0.38; 'show': 0.63; 'date,': 0.65; 'price': 0.66; '8bit%:100': 0.70; '8bit%:92': 0.70; '2013': 0.84 X-Received: by 10.49.96.196 with SMTP id du4mr2193086qeb.37.1361481735917; Thu, 21 Feb 2013 13:22:15 -0800 (PST) Newsgroups: comp.lang.python Date: Thu, 21 Feb 2013 13:22:15 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=94.68.75.81; posting-account=DYJQ-woAAACEPH85Au2BhUVfFTfSfVa4 References: <92536c34-cf00-4497-b646-ab79fa4ee062@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 94.68.75.81 MIME-Version: 1.0 Subject: Re: Checking for valid date input and convert appropriately From: Ferrous Cranus To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org 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: , Message-ID: Lines: 60 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361481745 news.xs4all.nl 6885 [2001:888:2000:d::a6]:39390 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39461 =CE=A4=CE=B7 =CE=A0=CE=AD=CE=BC=CF=80=CF=84=CE=B7, 21 =CE=A6=CE=B5=CE=B2=CF= =81=CE=BF=CF=85=CE=B1=CF=81=CE=AF=CE=BF=CF=85 2013 10:14:13 =CE=BC.=CE=BC. = UTC+2, =CE=BF =CF=87=CF=81=CE=AE=CF=83=CF=84=CE=B7=CF=82 MRAB =CE=AD=CE=B3= =CF=81=CE=B1=CF=88=CE=B5: > On 2013-02-21 19:38, Ferrous Cranus wrote: >=20 > > import datetime from datetime >=20 >=20 >=20 > Should be: >=20 >=20 >=20 > from datetime import datetime >=20 >=20 >=20 > > >=20 > > try: >=20 > > datetime.strptime( date, '%d %m %Y' ) >=20 >=20 >=20 > That parses the date and discards the result. >=20 >=20 >=20 > > date =3D date.strptime( '%Y-%m-%d' ) >=20 >=20 >=20 > 'date' is a string, it doesn't have a 'strptime' method. >=20 >=20 >=20 > When you parsed the date you got a datetime object; _that_ has the >=20 > 'strptime' method. I don't need to store the date i just want to make sure is entered correctl= y. I would like to have the user type the date like 21 02 2013 and then convert it to 2013-02-21 because thats how mysql wants the date in= order to store it. Please show me how to write this. Also, can you show me how to write it that if so even if the user entered d= ate is wrong it doesn't just crash the cgi-script?i know i can use tr: expe= ct: but i want to avoid it, somehow i need to check the date in the same if= statemnt like i do with the other user defined varibles for validity. if( task and ( price and price.isdigit() and price.__len__() <=3D 3 ) and (= date and datetime.strptime(date, '%Y-%m-%d') ) ): Thanks.