Well, I donβt know what your textBoxDate.Text class looks like , but I was able to make it work, compile and return the expected result.
TextBox textBoxDate = new TextBox();
textBoxDate.Text = string.Empty;
DateTime? date = (textBoxDate.Text != "") ? (DateTime?)DateTime.Parse(textBoxDate.Text) : null;
I think a clear tide (DateTime?)is what you need
source
share