Use the following to be sure that you have actually added date in the text box and then parse it:
string txtDate = TextBox2.Text;
DateTime date;
string theDate;
if (DateTime.TryParse(txtDate, out date))
{
theDate = date.ToString("yyyy-MM-dd");
}
now
theDate
variable will have your date in string format. You can use
date
variable it self if you want
date as DateTime