Thomas <
Tho...@discussions.microsoft.com> wrote:
> i have to check if a value is a valid date format depending on a "format
> string" the user specified. For example:
>
> Format String: "dd/mm/yyyy"
> Date Value: "01/12/2006"
> Valid: Yes!
>
> Format String: "yyyymmdd"
> Date Value: "01/01/2006"
> Valid: No!
>
> Format String: "dd.mm.yyyy"
> Date Value: "12/31/2006"
> Valid: No!
>
> Format String: "mm/dd/yyyy"
> Date Value: "12/31/2006"
> Valid: Yes!
>
> I always have the "dd", "mm" and "yyyy" values available, i also have the
> delimiter between them.
>
> So what is the best way to check for validation?
Have a look at DateTime.ParseExact, and DateTime.TryParseExact in .NET
2.0.
--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too