How to parse date from string ?
Posted
by Harikrishna
on Stack Overflow
See other posts from Stack Overflow
or by Harikrishna
Published on 2010-05-10T07:56:19Z
Indexed on
2010/05/10
8:04 UTC
Read the original article
Hit count: 424
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 ?
© Stack Overflow or respective owner