Programmer2015
Programmer2015

Reputation: 55

How to get the selected time from datetimepicker in C#

datetimepicker.Value or datetimepicker.Text is always returning the current DateTime, not the selected one. Is there any property that I need to set to get the selected date time. Below is my code:

private void button1_Click(object sender, EventArgs e)
{
    c1.cName = textBox1.Text;
    c1.dlv_Time = dateTimePicker1.Value;
    string temp = dateTimePicker1.Text;
    textBox1.Text = "";
    dateTimePicker1.Text = "";

}

In the Form UI, I am changing the time, but in the code Im always receiving the present time.

Thanks in advance

Upvotes: 0

Views: 2862

Answers (2)

QSS
QSS

Reputation: 41

dateTimePicker1.Value.TimeOfDay.ToString()

It will return you the selected time of the date picker control in the string format.

Upvotes: 1

Programmer2015
Programmer2015

Reputation: 55

I was editing a different timepicker and reading from a different timepicker. I have resolved it by changing datetimepicker1 to datetimepicker2.

Upvotes: 0

Related Questions