Check for valid date

Gerrit Holl gerrit.holl at pobox.com
Tue Jun 22 09:44:05 EDT 1999


On Tue, Jun 22, 1999 at 02:07:38PM +0200, Paolo G. Cantore wrote:
> From: "Paolo G. Cantore" <paolo.cantore at zxa.basf-ag.de>
> Newsgroups: comp.lang.python
> Subject: Re: Check for valid date
> Date: 	Tue, 22 Jun 1999 14:07:38 +0200
> To: python-list at python.org
> 
> Hi Remi,
> 
> I use a two-step procedure:  
> 
> >>>def check_date(year, month, day):
> ...	tup1 = (year, month, day, 0,0,0,0,0,0)
> ...  	try:
> ...    		date = time.mktime (tup1)
> ...    		tup2 = time.localtime (date)
> ...		if tup1[:2] != tup2[:2]:
> ...			return "Date not valid."
> ...		else:
> ...			return "Date valid."
> ...	except OverflowError:
> ...		return "Date not valid."
> ...
> >>> import time
> >>> print date_valid(1999,2,29)
> Date not valid.
> >>> print date_valid(1999,2,28)
> Date valid.
> 

I would return 0 or 1, instead of what you're doing.

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