Reputation: 335
I have a string coming from Data base in this format:
string DateNonFormat = "Feb 24, 1998";
Now I want to convert the format of this string to 1998,Feb 24 I tried this:
DateTime.ParseExact(DateNonFormat, "yyyy mm dd", CultureInfo.InvariantCulture);
But it gives Error of String was not recognized as a valid DateTime.
So I tried to convert the string into date but it converted the whole string into numeric date.2/24/1998
How can I take the Feb 24, 1998
to 1998,Feb 24
without converting it into Numeric date?
Upvotes: 0
Views: 116
Reputation: 2862
Ahmad, this should do the trick for you:
var DateNonFormat = @"Feb 24, 1998";
var newDate = DateTime.ParseExact(DateNonFormat, "MMM dd, yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy,MMM dd");
Console.WriteLine(newDate);
Upvotes: 1
Reputation: 52
You Should Try
string res = "Feb 24, 1998";
DateTime d = DateTime.ParseExact(res, "MMM dd, yyyy", System.Globalization.CultureInfo.InvariantCulture);
Output.Text=(d.ToString("MM/dd/yyyy"));
Upvotes: 2