1

when i assign the date to textBox of textmode= "date" ,it doesn't display and displays "mm/dd/yyy" although the textBox has the correct date in debugging and autopostBack is enabled .

DataTable dt= DepartMentDB.GetDepartmentById(ddlDepartment.SelectedValue.ToString());
string Managername = dt.Rows[0]["Dept_Manager"].ToString();
DateTime d = DateTime.Parse(dt.Rows[0]["Manager_hiredate"].ToString());
txtHiredate.Text = d.ToString("mm/dd/yyy");

2 Answers 2

2

You want "MM/dd/yyy" (notice the capital M. otherwise it would convert to minutes once its working). If it's still not working, use an invariant culture to force the conversion (since you are specifying the format directly). i.e.:

txtHiredate.Text = d.ToString("MM/dd/yyy", CultureInfo.InvariantCulture);

EDIT: Actually, it is because the textmode of date only support a specific format. Mainly yyyy-MM-dd or whatever the user specified in their culture settings. See https://stackoverflow.com/a/22747762/3419825

So either work with the text mode and go with yyyy-MM-dd, or remove the textmode, or use a framework like jQuery to add a mask

Sign up to request clarification or add additional context in comments.

Comments

1

Cast your value to DateTime object

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.