check whether the given date value is valid or not in python with django -
i need check whether given input value of date valid or not in python. used datetime.strptime check date. getting value error doesn't match format when given input value date '06-06-'. it's wrong want display output invalid.
if (datetime.strptime(s,'%m-%d-%y')): print "valid" else: print "invalid"
1 . s = '06-06-15' when given input value above, display correct output value "valid"
- s = '06-06-' when given input value above, getting error time data '06-13' not match format '%m-%d-%y'. want display output "invalid"
please suggest me that. in advance.
this how works.
valueerror raised if date_string , format can’t parsed time.strptime()
just turn
datetime.strptime(s,'%m-%d-%y'): print "valid" except valueerror: print "invalid"
Comments
Post a Comment