Reputation: 39
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");
Upvotes: 1
Views: 8841
Reputation: 2540
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
Upvotes: 2