I want to parse the date from the string where date formate can be any of different format.
Now to match date we can use DateTime.TryParseExact
and we can define format as we needed and date will be matched for any different format.
string[] formats = {"MMM dd yyyy"};
DateTime dateValue;
string dateString = "May 26 2008";
if (DateTime.TryParseExact(dateString, formats,
new CultureInfo("en-US"),
DateTimeStyles.None,
out dateValue))
MessageBox.Show(dateValue.ToString());
This matches with date.But this is not working for parse the date from the string that is it does not matched with the date which is in some string.
Like
if the date is "May 26 2008"
then we can define format "MMM dd yyyy"
and date will be matched.
But if date is in some string like "Abc May 26 2008"
then date will not be matched.So for that can we use regular expression here ? If yes how ?
The string from I want to parse the date, is parsed from the html page and the string can be any different.
EDIT : I want to write the format like which matches any string in which there is a date using regex.