IsDate in C#

  • Thread starter Thread starter Wayne
  • Start date Start date
W

Wayne

In VB6 there is a function IsDate that returns True if the expression is of type Date or is a string convertible to type Date; otherwise, it returns False. Is there such a built-in function in C#?
Thanks.
 
Wayne said:
In VB6 there is a function IsDate that returns True if the expression is of
type Date or is a string convertible to type Date; otherwise, it returns
False. Is there such a built-in function in C#?
Thanks.

You can use the DateTime.Parse() method. If it throws an exception, it isn't a
date:

try
{
System.DateTime dt = System.DateTime.Parse(str);
}
catch
{
// Not a date, handle appropriately
}
 
Thanks Julie! It works great.


Julie said:
You can use the DateTime.Parse() method. If it throws an exception, it isn't a
date:

try
{
System.DateTime dt = System.DateTime.Parse(str);
}
catch
{
// Not a date, handle appropriately
}
 
Back
Top