public bool IsValidDatetime(string strValue)
{
//return Convert.ToDateTime(strValue)
DateTime fromDateValue;
string s = "15/07/2012";
var formats = new[] { "dd/MM/yyyy", "yyyy-MM-dd" };
if (DateTime.TryParseExact(s, formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out fromDateValue))
{
return true;
// do for valid date
}
else
{
return false;
// do for invalid date
}
}
{
//return Convert.ToDateTime(strValue)
DateTime fromDateValue;
string s = "15/07/2012";
var formats = new[] { "dd/MM/yyyy", "yyyy-MM-dd" };
if (DateTime.TryParseExact(s, formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out fromDateValue))
{
return true;
// do for valid date
}
else
{
return false;
// do for invalid date
}
}
No comments:
Post a Comment