I\'m getting a string back from my page and I want to make sure it\'s a date. This is what I have so far (it works) and I just want to know if this is the \"best\" way to do it.
I would just TryParse the input string:
private bool ParseDateString()
{
var theIncomingParam = Request.Params.Get("__EVENTARGUMENT").ToString();
DateTime myDate;
if (DateTime.TryParse(theIncomingParam, CultureInfo.InvariantCulture, DateTimeStyles.None, out myDate))
{
int TheMonth = myDate.Month;
int TheDay = myDate.Day;
int TheYear = myDate.Year;
// TODO: further processing of the values just read
return true;
}
else
{
return false;
}
}