Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39486

Re: Checking for valid date input and convert appropriately

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!texta.sil.at!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <nikos.gr33k@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'case.': 0.05; 'method.': 0.05; 'mrab': 0.05; 'thats': 0.07; 'try:': 0.07; 'accepts': 0.09; 'be:': 0.09; 'input,': 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; 'personally,': 0.16; 're.search(': 0.16; 'wrote:': 0.17; 'string,': 0.17; 'thu,': 0.17; 'variables': 0.17; 'feb': 0.19; 'import': 0.21; 'defined': 0.22; 'posted': 0.22; "i'd": 0.22; 'cc:2**0': 0.23; 'task': 0.23; 'cc:no real name:2**0': 0.24; 'script': 0.24; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; "doesn't": 0.28; 'post': 0.28; '+0100,': 0.29; 'cgi': 0.29; 'crash': 0.29; 'convert': 0.29; 'this.': 0.29; 'that.': 0.30; 'correctly.': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'entered': 0.34; 'wrong': 0.34; 'received:209.85': 0.35; 'michael': 0.36; 'but': 0.36; 'should': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'store': 0.38; 'sure': 0.38; 'end': 0.40; 'think': 0.40; 'your': 0.60; '8bit%:95': 0.61; 'show': 0.63; 'within': 0.64; 'become': 0.65; 'date,': 0.65; 'price': 0.66; '8bit%:100': 0.70; '8bit%:92': 0.70; 'now:': 0.71; '2013': 0.84
X-Received by 10.49.127.198 with SMTP id ni6mr2126052qeb.23.1361488081956; Thu, 21 Feb 2013 15:08:01 -0800 (PST)
Newsgroups comp.lang.python
Date Thu, 21 Feb 2013 15:08:01 -0800 (PST)
In-Reply-To <mailman.2206.1361485261.2939.python-list@python.org>
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> <mailman.2190.1361477655.2939.python-list@python.org> <ca0a0004-2504-486f-9a82-3d1f6234932b@googlegroups.com> <mailman.2206.1361485261.2939.python-list@python.org>
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 <nikos.gr33k@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.2212.1361488829.2939.python-list@python.org> (permalink)
Lines 156
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1361488829 news.xs4all.nl 6973 [2001:888:2000:d::a6]:59166
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:39486

Show key headers only | View raw


Τη Παρασκευή, 22 Φεβρουαρίου 2013 12:03:59 π.μ. UTC+2, ο χρήστης Michael Ross έγραψε:
> On Thu, 21 Feb 2013 22:22:15 +0100, Ferrous Cranus <nikos.gr33k@gmail.com>  
> 
> wrote:
> 
> 
> 
> > Τη Πέμπτη, 21 Φεβρουαρίου 2013 10:14:13 μ.μ. UTC+2, ο χρήστης MRAB  
> 
> > έγραψε:
> 
> >> On 2013-02-21 19:38, Ferrous Cranus wrote:
> 
> >>
> 
> >> > import datetime from datetime
> 
> >>
> 
> >>
> 
> >>
> 
> >> Should be:
> 
> >>
> 
> >>
> 
> >>
> 
> >> from datetime import datetime
> 
> >>
> 
> >>
> 
> >>
> 
> >> >
> 
> >>
> 
> >> > try:
> 
> >>
> 
> >> >      datetime.strptime( date, '%d %m %Y' )
> 
> >>
> 
> >>
> 
> >>
> 
> >> That parses the date and discards the result.
> 
> >>
> 
> >>
> 
> >>
> 
> >> >      date = date.strptime( '%Y-%m-%d' )
> 
> >>
> 
> >>
> 
> >>
> 
> >> 'date' is a string, it doesn't have a 'strptime' method.
> 
> >>
> 
> >>
> 
> >>
> 
> >> When you parsed the date you got a datetime object; _that_ has the
> 
> >>
> 
> >> 'strptime' method.
> 
> >
> 
> > I don't need to store the date i just want to make sure is entered  
> 
> > correctly.
> 
> > 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 date is wrong it doesn't just crash the cgi-script?i know i can  
> 
> > use tr: expect: 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.
> 
> >
> 
> 
> 
> You *have* to try/expect in order to not have the script crash.
> 
> Think user typo: 21 02 2ß13
> 
> 
> 
> Personally, I'd use a javascript on the html so users can't POST invalid  
> 
> dates.
> 
> I use mootools for that. It accepts 21/02/2013, 21-02-2013 and 21.02.13 as  
> 
> input,
> 
> and you end up with 21.02.2013 posted to your cgi in any case.

i just want to check for date validity from within ha same if statemnt like i check the other variables and i tried a regualr expression just now:

if( task and ( price and price.isdigit() and price.__len__() <= 3 ) and ( date and re.search( r'(\d+) (\d+) (\d+)', date ) ) ):

Do i ahve somehting wrong in it?

will the if become true if the user enters 21 02 2013 ?

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-21 11:38 -0800
  Re: Checking for valid date input and convert appropriately MRAB <python@mrabarnett.plus.com> - 2013-02-21 20:14 +0000
    Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-21 13:22 -0800
      Re: Checking for valid date input and convert appropriately MRAB <python@mrabarnett.plus.com> - 2013-02-21 21:46 +0000
      Re: Checking for valid date input and convert appropriately "Michael Ross" <gmx@ross.cx> - 2013-02-21 23:03 +0100
        Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-21 15:08 -0800
          Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-21 15:18 -0800
            Re: Checking for valid date input and convert appropriately Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-21 23:30 +0000
          Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-21 15:18 -0800
          Re: Checking for valid date input and convert appropriately "Michael Ross" <gmx@ross.cx> - 2013-02-22 00:37 +0100
            Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-21 16:12 -0800
              Re: Checking for valid date input and convert appropriately "Michael Ross" <gmx@ross.cx> - 2013-02-22 01:57 +0100
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-21 20:34 -0800
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-21 20:34 -0800
                Re: Checking for valid date input and convert appropriately rob.marshall17@gmail.com - 2013-02-21 22:20 -0800
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-22 02:06 -0800
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-22 02:06 -0800
                Re: Checking for valid date input and convert appropriately rob.marshall17@gmail.com - 2013-02-21 22:20 -0800
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-22 03:01 -0800
                Re: Checking for valid date input and convert appropriately Lele Gaifax <lele@metapensiero.it> - 2013-02-22 13:03 +0100
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-22 05:24 -0800
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-22 05:28 -0800
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-22 05:28 -0800
                Re: Checking for valid date input and convert appropriately Lele Gaifax <lele@metapensiero.it> - 2013-02-22 14:35 +0100
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-22 07:07 -0800
                Re: Checking for valid date input and convert appropriately Lele Gaifax <lele@metapensiero.it> - 2013-02-22 16:25 +0100
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-22 09:38 -0800
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-22 09:39 -0800
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-22 09:39 -0800
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-22 09:38 -0800
                Re: Checking for valid date input and convert appropriately Tim Chase <python.list@tim.thechases.com> - 2013-02-22 10:18 -0600
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-22 07:07 -0800
                Re: Checking for valid date input and convert appropriately Chris Angelico <rosuav@gmail.com> - 2013-02-23 01:03 +1100
                Re: Checking for valid date input and convert appropriately Andreas Perstinger <andipersti@gmail.com> - 2013-02-22 15:10 +0100
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-22 05:24 -0800
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-22 03:01 -0800
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-22 03:45 -0800
                Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-22 03:45 -0800
            Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-21 16:12 -0800
        Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-21 15:08 -0800
    Re: Checking for valid date input and convert appropriately Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-02-21 13:22 -0800

csiph-web