how to calculatethe time?

  • Thread starter Thread starter Alan Ho
  • Start date Start date
A

Alan Ho

e.g.

Label17.Text=((DateTime.Parse(addEndText.Text))-(DateTime.Parse(addStartText
..Text))).ToString();

how can i calculate 10:00:00 - 20:00:00 then the result will ouput integer
and = 10

Thanks
 
Alan said:
e.g.

Label17.Text=((DateTime.Parse(addEndText.Text))-(DateTime.Parse(addStartText
.Text))).ToString();

how can i calculate 10:00:00 - 20:00:00 then the result will ouput integer
and = 10

Thanks

Do you just want the hours? If so, take the absolute value of the Hours
property of the TimeSpan that is returned by your date math operation:

TimeSpan ts =
DateTime.Parse(addEndText.Text)-DateTime.Parse(addStartText.Text)
Label17.Text = (Math.Abs(ts.Hours)).ToString();
 
fixed it..thx

Alan Ho said:
thx
If i want to 10:30:00 - 20:00:00
it's possible the output can be 10.5>?
thanks
Label17.Text=((DateTime.Parse(addEndText.Text))-(DateTime.Parse(addStartText
 
Back
Top