How to check the date validity?

Jason Friedman jsf80238 at gmail.com
Mon Dec 23 21:39:55 EST 2013


> In this file I have 3 different kind of fields: one consist of the
> sole date, one - sole time and one - datetime. The time includes
> milliseconds, i.e. "12:55:55.705"
> All fields of the file including those 3 I am reading as the string.
> All those strings after validating will go into mySQL table.

> I tried to do an RE, but its static validation and so will not work in
> all cases.

Not sure what you mean by static validation.  Would this not work?
import re
if re.search(r"\d{1,2}:\d{2}:\d{2}(.\d{1,3})?", "12:55:55.705"):
    # It's a time



More information about the Python-list mailing list