After this question has already received a good answer, in WinForms we can also set the Custom format to DateTimePicker Format , as Vivec said, this allows us to display the date / time in the specified format string in DateTimePicker, then it will be just as simple as we do. to get text from a TextBox.
// Set the Format type and the CustomFormat string. dateTimePicker1.Format = DateTimePickerFormat.Custom; dateTimePicker1.CustomFormat = "yyyy/MM/dd";

Now we can easily get the date by getting the text from DateTimePicker:
MessageBox.Show("Selected Date: " + dateTimePicker1.Text, "DateTimePicker", MessageBoxButtons.OK, MessageBoxIcon.Information);

NOTE. If you plan to embed data only by date in the date column type in SQL, see this documentation for the supported string literary formats for the date . You cannot insert a date in a ydm format string because it is not supported:
dateTimePicker1.CustomFormat = "yyyy/dd/MM"; var qr = "INSERT INTO tbl VALUES (@dtp)"; using (var insertCommand = new SqlCommand.. { try { insertCommand.Parameters.AddWithValue("@dtp", dateTimePicker1.Text); con.Open(); insertCommand.ExecuteScalar(); } catch (Exception ex) { MessageBox.Show("Exception message: " + ex.Message, "DateTimePicker", MessageBoxButtons.OK, MessageBoxIcon.Error); }
the above code ends with the following Exception: 
Know. Greetings.
WhySoSerious Jan 20 '14 at 8:09 2014-01-20 08:09
source share