Good day All,
Before this, I have a c# system in a VM with Microsoft Window XP. I have some code to convert string to date time, the following is part of my code :
DateTime allowDateTime = DateTime.Now.AddMonths(-2);
string formatted = allowDateTime.ToString("M/dd/yyyy");
DateTime dt = Convert.ToDateTime(formatted);
if (redempDateConvert < dt)
td.Text = "";
Until this point, everything is working fine. After that, I move my all source code without any changes, and data base and set it up in my real machine (Window 7).
System is working fine, I am still able to log in and control the system like usual.
Until today, I have reach to this part, and browser displayed error message :
String was not recognized as a valid DateTime.
in line 397.
Here I displayed my code again (with explanation):
DateTime allowDateTime = DateTime.Now.AddMonths(-2);
string formatted = allowDateTime.ToString("M/dd/yyyy");
DateTime dt = Convert.ToDateTime(formatted); //here is line 397, which is the error happening.
if (redempDateConvert < dt)
td.Text = "";
I have checked both (VM and my real machine) environment, both running in .Net 4.0.
Just curious on why the same code, but there is an error happen in my real machine. Is that I miss out to configure something? Kindly advise.