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

Last Reply 5 months ago By dharmendr

Posted 5 months 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 5 months ago
Hi @GuruLogu,
Please try the following

Convert dd/mm/yyyy format string to DateTime in c# .Net

It might help you.

Cheers Andrea.

Posted 5 months ago

Thanks Andrea!

But I need in MVC

Posted 5 months 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: