Error: 'String was not recognized as a valid DateTime format dd/MM/yyyy' in ASP.Net MVC

Last Reply one year ago By dharmendr

Posted one year ago

Code Behind in Controller 

string _pckdate = Convert.ToDateTime(Request.Form["txtpickupdate"]).ToShortDateString() + " " + Convert.ToDateTime(Request.Form["txtpickuptime"]).ToShortTimeString();
adbook.pickupdate_ = DateTime.ParseExact(_pckdate, "MM/dd/yyyy HH:mm tt", System.Globalization.CultureInfo.InvariantCulture);

it will shows an error: "String was not recognized as a valid DateTime “ format dd/MM/yyyy”?"

Posted one year ago

Hi GuruLogu,

Refer the below code.

string dateString = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
DateTime dt = new DateTime();
string result;
    result = Convert.ToDateTime(dateString).ToString("MM/dd/yyyy HH:mm tt", CultureInfo.InvariantCulture);
    dt = Convert.ToDateTime(result);
catch (FormatException)


I agree, here is the link: