How to Convert Date(from date time input field) to another date format in C#?

Posted by Saeed Khan on Stack Overflow See other posts from Stack Overflow or by Saeed Khan
Published on 2013-10-30T09:45:28Z Indexed on 2013/10/30 9:54 UTC
Read the original article Hit count: 262

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

© Stack Overflow or respective owner

Related posts about c#

Related posts about date