Check for valid date

Gerrit Holl gerrit.holl at pobox.com
Mon Jun 21 16:39:50 EDT 1999


On Mon, Jun 21, 1999 at 04:44:20PM +0000, Remi Delon wrote:
> From: Remi Delon <rdelon at my-deja.com>
> Newsgroups: comp.lang.python
> Subject: Check for valid date
> Date: 	Mon, 21 Jun 1999 16:44:20 GMT
> To: python-list at python.org
> 
> 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)

Right. strptime does what it has to do, it parses the given string.

> >>> mktime((1999, 2, 30, 0, 0, 0, 61, 0))
> 920361600.0

But this should raise an error, in my opinion. Hmm... what about
DateError?

> >>> ctime(920361600.0)
> 'Tue Mar  2 00:00:00 1999'
> 
> Is there a way to check test whether the day actually exists or not ?
> 
groeten,
Gerrit.

-- 
The Dutch Linuxgames homepage:	http://linuxgames.nl.linux.org
Personal homepage:		http://www.nl.linux.org/~gerrit/

Discoverb is a python program in Dutch and English which tests the words you
learned by asking it. Homepage: http://www.nl.linux.org/~gerrit/discoverb/




More information about the Python-list mailing list