I have two textboxes. One for a clock in time and one for clock out. The times will be put in this format:
Hours:Minutes
Lets say I have clocked in at 7:00 AM and clocked out at 2:00 PM.
With my current code, I get a difference of 2 hours, but it should be 7 hours. How would I do that in C#. I was going to convert to the 24 hour, by letting the user select AM or PM, but I got confused.
So, basically, how would I calculate the difference of hours between the two times?
I tried this, but got 2 hours and not 7 when I plugged in the numbers.
DateTime startTime = Convert.ToDateTime(textBox1.Text);
DateTime endtime = Convert.ToDateTime(textBox2.Text);
TimeSpan duration = startTime - endtime;
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…