I get the following error when i try to convert to date time.
String was not recognized as a valid DateTime.
cost.b_date =
Try using DateTime.ParseExact.
DateTime date = DateTime.ParseExact(c_date.Text, "yyyy/MM/dd", null);
Using string.Format
when the input is a string is pointless.
If you know the format of the string, you should use DateTime.ParseExact or DateTime.TryParseExact. For example, for the string you've got, you could use:
DateTime date = DateTime.ParseExact(text, "MM/dd/yyyy",
CultureInfo.InvariantCulture);
You should consider:
TryParseExact
to detect user error more easily without an exception.DateTime
to start with, that would be preferable.CultureInfo provider = CultureInfo.InvariantCulture;
DateTime result = DateTime.ParseExact(c_date.Text, "d", provider);