Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39535
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-02-22 02:06 -0800 |
| References | (5 earlier) <mailman.2216.1361489840.2939.python-list@python.org> <49de0696-b6f6-42ce-9272-79dac37c9605@googlegroups.com> <mailman.2230.1361494634.2939.python-list@python.org> <mailman.2236.1361507671.2939.python-list@python.org> <ceca99e1-c51a-4b31-8a73-de7f46bf4353@googlegroups.com> |
| Subject | Re: Checking for valid date input and convert appropriately |
| From | Ferrous Cranus <nikos.gr33k@gmail.com> |
| Message-ID | <mailman.2246.1361527594.2939.python-list@python.org> (permalink) |
Τη Παρασκευή, 22 Φεβρουαρίου 2013 8:20:20 π.μ. UTC+2, ο χρήστης rob.mar...@gmail.com έγραψε:
> The datetime function: strptime() DOES check the date for validity. So try something like:
>
>
>
> from datetime import datetime
>
>
>
> def get_date():
>
> while True:
>
> try:
>
> date_in = raw_input("Enter date (dd mm yyyy): ")
>
> date_out = datetime.strptime(date_in,"%d %m %Y").strftime("%Y-%m-%d")
>
> return date_out
>
> except ValueError:
>
> print "Invalid date: {}, try again...".format(date_in)
Thank you very very much!! i cannot beleive that it was so easy, a matter of one line of coding!
date = datetime.strptime(date,"%d %m %Y").strftime("%Y-%m-%d")
Cna you please explain in to me?
This line checks the date variable for valid pattern entry and then also tranforms the date to the othjer pattern?
And if there is a way to embed this line to the existing if() statemtn along with the othwr variables check that would be perfect!!
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