Friday 12 May 2017

An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll

An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll

Additional information: String was not recognized as a valid DateTime.

I got above error, but same code was working from another system.

My config:
    <add key="sDate" value="16-02-2012 11:13:23"/>

Root cause: The system which i am running the code is having local date format as DD/M/YYYY
But the my input is having MM/DD/YYYY

Solution:
Option 1: Change sDate from    <add key="sDate" value="16-02-2012 11:13:23"/> Value to
<add key="sDate" value="02-16-2012 11:13:23"/>

Option 2: Change system date format to MM/DD/YYYY