Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39517
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-02-21 20:34 -0800 |
| References | (3 earlier) <mailman.2206.1361485261.2939.python-list@python.org> <5bac38bb-df2e-47b8-96dd-2b1c090959e4@googlegroups.com> <mailman.2216.1361489840.2939.python-list@python.org> <49de0696-b6f6-42ce-9272-79dac37c9605@googlegroups.com> <mailman.2230.1361494634.2939.python-list@python.org> |
| Message-ID | <6811dbe3-8574-4b96-836f-6c9828b06edc@googlegroups.com> (permalink) |
| Subject | Re: Checking for valid date input and convert appropriately |
| From | Ferrous Cranus <nikos.gr33k@gmail.com> |
Τη Παρασκευή, 22 Φεβρουαρίου 2013 2:57:03 π.μ. UTC+2, ο χρήστης Michael Ross έγραψε:
> On Fri, 22 Feb 2013 01:12:40 +0100, Ferrous Cranus <nikos.gr33k@gmail.com>
> 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'
Tis seems very nice solution but also we need to check the user input for validity. What if the user entered: 29 15 2013 ?
i tried to use your method applying some date validation check but that also failed for me:
try:
if( datetime.strptime(date, '%d m% %Y') ):
day, month, year = int(date[:2]), int(date[3:5]), int(date[6:])
date = date(year, month, day)
date = date.strftime('%Y-%m-%d')
except:
print "....."
========================
Isn't method strptime check the user input for validity?
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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