Validating date format, not in rules

I’m taking a date from a csv file, and I want to put it into a table, whether it’s in a valid format or not (so the user can correct it later). This means I cannot use rules, as it would reject it altogether. I have a separate field to say whether or not the date is valid.

My question is how do I test this value to see if it’s in the date format I want, and just get a true/false answer? I can’t work out how to use CDateValidator.

Why don’t you use preg_match instead?

If I’m right, CValidator and its children are meant for checking user inputs. Because you are importing data from csv file, there’s no need to use CDateValidator.

If you want to check whether a date is not just in the right format fx 2012-04-22 but also a legal date, you can use first preg_match as softark suggests and then afterwards use an appropriate php date-time function to check if it is a invalid date (fx. 2012-99-99). I think you can use strtotime or mktime, which both returns false on invalid input.

there this checkdate function