Ashish Ashish - 2 months ago 12
ASP.NET (C#) Question

Calendar Extender date picking and converting into correct format

i am picking the value from calender extender in textbox and i am getting the value in the format

{"MM/dd/yyyy"}
but i want it in the format
{"dd/MM/yyyy"}
in another textbox
(
txt_actualrightformat.Text
) as code shown below

DateTime wrongformat = DateTime.Parse(TextBox4.Text);
String rightformat = String.Format("{0:dd/MM/yyyy}", wrongformat.Date);
txt_actualrightformat.Text = rightformat.ToString();

Answer

DateTime is irespective of the format, format is only for displaying purpose. If you are not getting the right date in wrongformat then you can use DateTime.ParseExact with the format. and then simply

txt_actualrightformat.Text = wrongformat.ToString("dd/MM/yyyy");

EDIT:

use DateTime.ParseExcat like:

DateTime dt = DateTime.ParseExact(TextBox4.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture);
txt_actualrightformat = dt.ToString("dd/MM/yyyy");