verifying date values
dsavitsk
dsavitsk at e-coli.net
Sun Jun 25 13:13:21 EDT 2000
i needed to accept both a string of characters '12042000' as well as a list
of formatting parameters 'MMDDYYYY' and see if the date when formatted by
the params was a date, and if not why. i ended up just writing a little
function myself. thanks though.
"richard_chamberlain" <richard_chamberlain at ntlworld.com> wrote in message
news:My355.514$F01.10888 at news6-win.server.ntlworld.com...
> Hi,
>
> Marc Lemburg's mxDateTime module (do a search at www.vex.net/parnassus)
> returns a RangeError if you create a date that doesn't exist. I've created
a
> checkDate method below which returns 0 or 1.
>
> mxDateTime is an excellent module if you're going to be doing anything
> complicated with dates or times.
>
> Richard
>
> import DateTime
>
> def checkDate(y,m,d):
> "year,month,day"
> try:
> checkDate=DateTime.DateTime(y,m,d)
> except DateTime.RangeError:
> return 0
> else:
> return 1
> def testDates(y,m,d):
> print '%d/%d/%d' %(y,m,d)
> if checkDate(y,m,d):
> print 'is ok'
> else:
> print 'is not valid'
>
> def main():
> testDates(2000,3,10)
> testDates(2000,13,3)
>
> if __name__=='__main__':
> main()
>
>
> dsavitsk <dsavitsk at e-coli.net> wrote in message
> news:PcQ45.16280$dF.645882 at news1.rdc1.il.home.com...
> > is there a quick way to see if a string is a valid date? something like
> >
> > >>> isDate('5/22/1999')
> > 1
> >
> > thanks
> >
> >
> >
>
>
More information about the Python-list
mailing list