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

Last Reply one month ago By dharmendr

Posted one month 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”?"

You are viewing reply posted by: dharmendr one month ago.
Posted one month 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: