Check for valid date

scott cotton scott at chronis.pobox.com
Mon Jun 21 23:22:37 CEST 1999


you could try making sure that 

strftime(your_format, strptime(date2check, your_format)) == date2check.

and checking for OverflowError & ValueError in the process.

scott



On Mon, Jun 21, 1999 at 04:44:20PM +0000, Remi Delon wrote:
| Hi, I'm trying to use the time module to check whether a date is
| actually a valid day or not.
| Unfortunately, it looks like the strptime function only performs a basic
| range check. (for example, it will accept 02/30/199)
| Here is a little test I did:
| 
| >>> strptime('02/30/1999','%m/%d/%Y)
| (1999, 2, 30, 0, 0, 0, 61, 0)
| >>> mktime((1999, 2, 30, 0, 0, 0, 61, 0))
| 920361600.0
| >>> ctime(920361600.0)
| 'Tue Mar  2 00:00:00 1999'
| 
| Is there a way to check test whether the day actually exists or not ?
| 
| 
| I also have a totally different problem : I'm trying to get python 1.5.2
| to run with Tcl/Tk 8.1. Has anyone been able to do that on AIX ?
| I found 2 patches for tkinter that were supposed to fix the problems,
| but unfortunately, they don't work for AIX.
| 
| Thanks
| 
| Remi.
| 
| 
| Sent via Deja.com http://www.deja.com/
| Share what you know. Learn what you don't.
| 
| -- 
| http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list