Vishwas Kadamannaya

Vishwas Kadamannaya

  • 1.6k
  • 122
  • 143k

Time Span Diffrences Problem

Apr 5 2011 1:51 AM
Hi All,
      I have a datatable that contains travel details
TravelDateSourceDestinationDepartureTimeArrivalTimeDuration



 10:00:00 12:00:00  2



  12:00:00  1:00:00 -11

I am getting all the values in datatable except "Duration", I need to calculate duration based on Departure and Arrival Time . 
      I am using the below step to do that but some time it gives wrong values

  Foreach(DataRow dr in dt.Rows)
  {
   TimeSpan ts1 = TimeSpan.Parse(dr["DepartureTime"].ToString());     TimeSpan ts2 = TimeSpan.Parse(dr["ArrivalTime"].ToString());
     TimeSpan ts3 = ts2.Subtract(ts1);
    dr["Duration"]=ts3.ToString();
   }
 In second row it gives wrong value . How to rectify this..


Thanks in Advance

Answers (3)