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.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Feb 5, 2013, 10:42 PM
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.
VulpesPosted Feb 5, 2013, 1:59 PM