I am trying to convert from string to DataTime but an an error occurs. I am using VS 2003, .NET Framework 1.1
DateTime dt = Convert.ToDateTime("11/23/2010");
string s2 = dt.ToString("dd-MM-yyyy");
DateTime dtnew = Convert.ToString(s2);
Cannot implicitly convert type 'string' to 'System.DateTime'
Can any one help me me with the syntax how to solve the error.
string input = "21-12-2010"; // dd-MM-yyyy
DateTime d;
if (DateTime.TryParseExact(input, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out d))
{
// use d
}
I guess that you have made a typo - change Convert.ToString(s2)
to Convert.ToDateTime(s2)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With