Shafiqq Aziz

Shafiqq Aziz

  • NA
  • 54
  • 11.9k

C# Multiple Time Duration Calculation

Nov 1 2017 2:29 AM
Hi, i have a problem here which is my output for my calculation is wrong.
 
I have 4 dateTimePicker using custom format as HH:mm named dtpIn1, dtpOut1, dtpIn2, dtpOut2. My target calculation are duration between dtpOut1 to dtpIn1, duration between dtpOut2 to dptIn2 and total duration between dtpOut1 to dtpIn2.
 
I got right output on calculation dtpOut1 to dtpIn1 and dtpOut1 to dtpIn2 and got very wrong on dtpOut2 to dtpIn2. What is wrong with my code here? Can you guys help me?
 
Here's my code :
 
//Calculation for time total and time sum start
private void dtpIn1_ValueChanged(object sender, EventArgs e)
{
TimeSpan result = this.dtpIn1.Value - this.dtpOut1.Value;
this.txtTotal1.Text = result.ToString();
}
private void dtpOut2_ValueChanged(object sender, EventArgs e)
{
TimeSpan result = this.dtpIn2.Value - this.dtpOut2.Value;
this.txtTotal2.Text = result.ToString();
}
private void dtpIn2_ValueChanged(object sender, EventArgs e)
{
TimeSpan result = this.dtpIn2.Value - this.dtpOut1.Value;
this.txtSum.Text = result.ToString();
}
//Calculation for time total and time sum end
 

Answers (8)