J
John Livermore
In C# what is the best way to validate that a particular string
entered by a user will actually convert to a date w/o using a try
catch block or writing code to explicitly parse the string?
Here is what I know I can use, but there are potentially thousands of
dates to validate, and I know this code is inefficient if there are
lots of dates that won't convert...
private DateTime ValidateDate(string date)
{
DateTime convertedDate = DateTime.MinValue;
try
{
convertedDate = DateTime.Parse(date);
}
catch
{
// throw exception for invalid date
}
return convertedDate;
}
Thanks,
John
entered by a user will actually convert to a date w/o using a try
catch block or writing code to explicitly parse the string?
Here is what I know I can use, but there are potentially thousands of
dates to validate, and I know this code is inefficient if there are
lots of dates that won't convert...
private DateTime ValidateDate(string date)
{
DateTime convertedDate = DateTime.MinValue;
try
{
convertedDate = DateTime.Parse(date);
}
catch
{
// throw exception for invalid date
}
return convertedDate;
}
Thanks,
John