[Tutor] Checking for a Valid Date

John Fouhy john at fouhy.net
Tue Sep 2 06:25:35 CEST 2008


2008/9/2 Wayne Watson <sierra_mtnview at sbcglobal.net>:
> Is there some method or function that checks whether a date is valid. For
> example, these are not valid (yyyy/mm/dd format here for reference.):
[...]
> Perhaps a Try is useful with some function?

Yup.  Have a look at time.strptime.

Don't be afraid to look through the standard library documentation.
If you're doing stuff with times and dates, reading through the time
and datetime modules would be very helpful.
(generally you will want to use datetime.  The time module is at a
lower level, although it is still the place to go for docs on
strptime/strftime format strings)

-- 
John.


More information about the Tutor mailing list