Detects if a string can be parsed to a valid date.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under Visual Studio category on | Points: 40 | Views : 849
Using DateTime.Parse method ,we can check whether string is a valid date or not.If string date is valid,then it will return True otherwise return False.
public bool IsDate(this string astrText)
{
try
{
System.DateTime dtDateTime = System.DateTime.Parse(astrText);
}
catch
{
return false;
}

return true;
}

Comments or Responses

Login to post response