Check Date Format

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
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?

Thanks in advance.
Thomas
 
Thomas said:
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.
 
Back
Top