Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I check a date is valid? 1

Status
Not open for further replies.

James1981

Programmer
Nov 2, 2002
76
US
Hi,

I need to check a date that a user has entered is valid, taking account of days in a month and leap years.

For example 31-Feb-03 Would always be invalid.

is there a Function in DateTime that can check such a thing?

Cheers
James
 
IsDate(datestring)

returns a boolean indicated if the string can be converted to a date. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Mark,

Tried using this but it doesn't seem to work - is this method VB.net only? I am using c#...

James
 
James

string myDate = "1/10/2002";

try
{
DateTime dt = DateTime.Parse(myDate);
}
catch
{
// invalid date if this is executed
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top