how to add times from two datetimepicker
Hi experts.....I have two datetime picker controls from that I want to find out total times please help me out...thanks n advance
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Soft CornerPosted May 3, 2011, 2:52 AM
If u want to calculate exact difference between two datetimepicker then on ValueChanged event u can do like this :
private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
{
DateTime date1, date2;
date1 = Convert.ToDateTime(dateTimePicker1.Value);
date2 = Convert.ToDateTime(dateTimePicker2.Value);
System.TimeSpan diff;
diff = date2 - date1;
MessageBox.Show("Difference is Days :" + diff.Days + " Time" + diff.Hours + ":" + diff.Minutes + ":" + diff.Seconds);
}
Note : I have calculated difference when value changed for datetimepicker2
Ankit NandekarPosted May 3, 2011, 2:36 AM
MessageBox.Show((dateTimePicker1.Value - dateTimePicker1.Value).ToString());