Quote Originally Posted by marniel647 View Post
Yes i agree with dun. It is better to use the DT picker. But Dt picker returns long date. so f you want to get only the yyyy-mm-dd you can use the .format method in your string.
That's not correct. The DateTimePicker can display any format you want but the format that it displays is irrelevant when it comes to using the data. The most important property of the DateTimePicker is Value, which is type DateTime. You should almost never be using the Text property. Because the Value property is a DateTime, format is completely irrelevant. A DateTime is a binary representation of a date and time, not text. Format is only relevant when converting to or from text. If there's no text then there's no format.

In the original code, the String from the TextBox is being converted to a DateTime first and then that is being converted back to a String. That's wring on two counts. You should be using a DateTimePicker as suggested and getting the DateTimne from it and inserting that. DO NOT convert anything that is not text into text.