Check for valid date
Paolo G. Cantore
paolo.cantore at zxa.basf-ag.de
Tue Jun 22 08:07:38 EDT 1999
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.
Paolo
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.
--
/* Paolo G. Cantore paolo.cantore at basf-ag.de */
/* BASF AG ZOI/AP Zentralabteilung Informatik */
/* D-67056 Ludwigshafen Tel. +49-621-60-43987 */
/* Germany Fax. +49-621-60-20833 */
More information about the Python-list
mailing list