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


Groups > comp.lang.python > #39451 > unrolled thread

Checking for valid date input and convert appropriately

Started byFerrous Cranus <nikos.gr33k@gmail.com>
First post2013-02-21 11:38 -0800
Last post2013-02-21 13:22 -0800
Articles 1 on this page of 41 — 9 participants

Back to article view | Back to comp.lang.python


Contents

  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

Page 3 of 3 — ← Prev page 1 2 [3]


#39461

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-02-21 13:22 -0800
Message-ID<mailman.2198.1361481745.2939.python-list@python.org>
In reply to#39452
Τη Πέμπτη, 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.

if( task and ( price and price.isdigit() and price.__len__() <= 3 ) and ( date and datetime.strptime(date, '%Y-%m-%d') ) ):

Thanks.

[toc] | [prev] | [standalone]


Page 3 of 3 — ← Prev page 1 2 [3]

Back to top | Article view | comp.lang.python


csiph-web