how to chnage date format from dd-MM-yy to MM-dd-yy in asp.net
I have date "22-12-2012"
i want to change into "12-22-2012"
when i try to convert it gives me error
String was not recognized as a valid DateTime.
Change date from "22-12-2012" to "12-22-2012"
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

VulpesRank #55 · 29.2K reputationPosted Feb 5, 2013, 8:59 AM EST
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 5, 2013, 5:42 PM EST
you may also use TryParseExact...
try.
DateTime newdate;
var isDate = DateTime.TryParseExact("22-12-2013", "dd-MM-yyyy", null, System.Globalization.DateTimeStyles.None,out newdate);
string myformatDate;
if (isDate)
{
myformatDate = newdate.ToString("MM-dd-yyyy");
}
else
{
myformatDate = DateTime.Now.ToString("MM-dd-yyyy");
}
hope this will help you.