Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Check Date Format

0 views
Skip to first unread message

Jon Skeet [C# MVP]

unread,
Mar 3, 2006, 4:57:39 AM3/3/06
to
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

0 new messages