There are various ways you could do this; following are just examples. Note
that I have used TotalHours (not Hours) to avoid the scenario where it has
taken over a day, hence test case of 38 hours.
TimeSpan ts = new TimeSpan(38, 45, 23);
Console.WriteLine("{0}:{1}:{2}:{3}", ts.Days, ts.Hours,
ts.Minutes, ts.Seconds);
Console.WriteLine(ts.TotalHours); // simplest (decimal) - but
includes seconds & ms etc
// round to hours and minutes only (is there an easier way?)
int hours = (int)Math.Floor(ts.TotalHours), minutes =
ts.Minutes;
TimeSpan ts2 = new TimeSpan(hours, minutes, 0);
Console.WriteLine(ts2.TotalHours); // decimal number of hours
Console.WriteLine("{0}.{1}", hours, minutes); // hours.minutes
Console.ReadLine();
Hope something in there is useful.
Marc
"gh" <gh@at.ne> wrote in message
news:uN*************@TK2MSFTNGP15.phx.gbl...
I have 2 columns in a grid where the user enters a begining time(TI) and at
the end of the day an end time(TO). I then want to take the TO - TI to get
the difference and display it as hours and minutes. If the result is 7
hours and 45 minutes I would like it to be able to display it 2 ways, as
7.45 or 7.75, if it was 8 hours then display 8.00. I have the code below
to do the subtraction, but I am not able to get the result converted to a
double.
TI = colTimeIn;
TO = colOut;
TimeResult = TO.Subtract(TI);
double aTime = Convert.ToDouble(TimeResult);<--- Errors here
How would I get the the conversion and be able to store it as a double?
TIA