Reputation: 25553
Suppose I have date string like mydate = "24-Jun-2011";
I want to convert it to another format "2011-06-24".
What is the simple way to do this?
Upvotes: 2
Views: 7052
Reputation: 2344
http://www.csharp-examples.net/string-format-datetime/ has a lot of different formatting options... This should work well for you.
Upvotes: 0
Reputation: 27913
DateTime.ParseExact("24-Jun-2011", "dd-MMM-yyyy").ToString ("yyyy-MM-dd")
See formats here at MSDN.
Upvotes: 7
Reputation: 3681
U can Parse
it to DateTime
and then using tostring
+ special format get what u need
Upvotes: 1
Reputation: 46575
The best way is to parse the string to a DateTime and then convert it to a string again.
Be sure to have a look at the documentation for DateTime.Parse, DateTime.TryParse and DateTime.ToString
DateTime.Parse(myDate).ToString("yyyy-MM-dd");
Upvotes: 19