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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'skip:% 20': 0.07; 'try:': 0.07; 'valueerror:': 0.07; 'function:': 0.09; 'subject:skip:a 10': 0.09; 'to:addr:comp.lang.python': 0.09; '{},': 0.09; 'cc:addr :python-list': 0.10; 'def': 0.10; '"invalid': 0.16; "'%d": 0.16; 'true:': 0.16; 'import': 0.21; '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; 'date:': 0.29; 'print': 0.32; 'like:': 0.33; 'skip:d 20': 0.34; 'received:google.com': 0.34; 'something': 0.35; 'except': 0.36; 'does': 0.37; 'subject:: ': 0.38; '8bit%:95': 0.61; 'email addr:gmail.com': 0.63; 'price': 0.66; '8bit%:100': 0.70; '8bit%:92': 0.70; '2013': 0.84 X-Received: by 10.49.48.41 with SMTP id i9mr60120qen.36.1361530882761; Fri, 22 Feb 2013 03:01:22 -0800 (PST) Newsgroups: comp.lang.python Date: Fri, 22 Feb 2013 03:01:22 -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> <5bac38bb-df2e-47b8-96dd-2b1c090959e4@googlegroups.com> <49de0696-b6f6-42ce-9272-79dac37c9605@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: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361530885 news.xs4all.nl 6873 [2001:888:2000:d::a6]:54951 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39542 =CE=A4=CE=B7 =CE=A0=CE=B1=CF=81=CE=B1=CF=83=CE=BA=CE=B5=CF=85=CE=AE, 22 =CE= =A6=CE=B5=CE=B2=CF=81=CE=BF=CF=85=CE=B1=CF=81=CE=AF=CE=BF=CF=85 2013 8:20:2= 0 =CF=80.=CE=BC. UTC+2, =CE=BF =CF=87=CF=81=CE=AE=CF=83=CF=84=CE=B7=CF=82 r= ob.mar...@gmail.com =CE=AD=CE=B3=CF=81=CE=B1=CF=88=CE=B5: > The datetime function: strptime() DOES check the date for validity. So tr= y something like: >=20 >=20 >=20 > from datetime import datetime >=20 >=20 >=20 > def get_date(): >=20 > while True: >=20 > try: >=20 > date_in =3D raw_input("Enter date (dd mm yyyy): ") >=20 > date_out =3D datetime.strptime(date_in,"%d %m %Y").strftime("%Y-%m-= %d") >=20 > return date_out >=20 > except ValueError: >=20 > print "Invalid date: {}, try again...".format(date_in) I'am thinking if somehting like the follwoing work: if( task and ( price and price.isdigit() and price.__len__() <=3D 3 ) and (= date and eval( datetime.strptime(date, '%d %m %Y').strftime('%Y-%m-%d') ) = ) ):