How to Convert Date(from date time input field) to another date format in C#?
- by Saeed Khan
I have Date time input field from where I am taking date and converting it to another format, my code for that
try
{
DateTime dt = dtiFrom.Value.Date;
string format = "DD-MM-YYYY"; // Use this format
MessageBox.Show(dt.ToString(format)); // here its shows result as DD-10-YYYY
DateTime dt1 = Convert.ToDateTime(dt.ToString(format)); // here Error "The string was not recognized as a valid DateTime. There is an unknown word starting at index 0."
}
catch (Exception ee)
{
MessageBox.Show(ee.Message, "Error Message!");
}
I am not able to convert date according to my format. please could any body help me in code or suggest me some code. thanks in advance