bob gailer wrote:
Eric Dorsey wrote:
Greetings,
I have a program where I ask a user to enter a date in format
YYYY-MM-DD, and get a string like: '2008-10-25'
Can anyone tell me how I would verify this is a real date before
allowing it to be passed on to the next part of the program?
Take a look at the time module and it's strptime function.
>>> import time
>>> time.strptime("2008-10-25", "%Y-%m-%d") ## CORRECTED
(2008, 10, 25, 0, 0, 0, 5, 299, -1)
>>> time.strptime("2008-10-125", "%Y-%m-%d")
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "H:\Python25\lib\_strptime.py", line 313, in strptime
data_string[found.end():])
ValueError: unconverted data remains: 5
--
Bob Gailer
Chapel Hill NC
919-636-4239
When we take the time to be aware of our feelings and
needs we have more satisfying interatctions with others.
Nonviolent Communication provides tools for this awareness.
As a coach and trainer I can assist you in learning this process.
What is YOUR biggest relationship challenge?
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor