Reputation: 2203
I have a "string" in format mm/dd/yyyy and want to change this to "Feb 2, 2011".
Can this be done using Convert.ToDateTime?
Thanks Behrouz
Upvotes: 0
Views: 11804
Reputation: 2204
Try This:
string test = "1/21/2011";
string result = Convert.ToDateTime(test).ToLongDateString();
MessageBox.Show(result);
Regards!
Upvotes: 0
Reputation: 1893
You need to convert your string to DateTime First and then Convert to string using required format
String.Format("{0:MMM d, yyyy}", Convert.ToDateTime(date));
Here is link
Upvotes: 4
Reputation: 7639
Use Convert.ToDateTime(string date,IFormatProvider provider) where the format provider should be "{0:dddd, MMMM d, yyyy}".
Upvotes: 0
Reputation: 27339
This code should work:
var dateString = "02/02/2011";
Console.WriteLine(DateTime.Parse(dateString).ToString("MMM d, yyyy"));
Upvotes: 1
Reputation: 50038
DateTime dateObject= DateTime.Parse(yourDateString);
dateObject.ToString("MMMM dd, yyyy")
or in single line
string result = DateTime.Parse(yourDateString).ToString("MMMM dd, yyyy");
Upvotes: 3