I have an application where i show Flight Departure Date and Arrival Date and Flight Time Duration.
For Flight Time Duration , i simply subtract dates which gives me TimeStamp like
TimeStamp duration = arrivalDate.subtract(departureDate);
so record is like
Departure Arrival Duration
Sat 07:05A Sat 09:20A 2h 15m
Sat 10:10A Sat 11:15A 1h 05m
Sat 05:15P Sat 07:16P 2h 01m
Total Duration 5h 21m
I have many such flight records and i need to show Total Flight Duration , for this
i simply add Time span like
TimeStamp totalDuration = totalDuration.Add(duration);
But i got a situation where totalDuration reaches a value like {1.02:10:00} and when trying to convert this value to DateTime like this
TotalConnectionTime = new DateTime(2012,06, 30,(int)totalDuration.TotalHours, totalDuration.Minutes, 0);
it gives error
“Hour, Minute, and Second parameters describe an un-representable DateTime.”
(int)totalDuration.TotalHours = 26 and this create problem
I need to covert to {1.02:10:00} to 26h 10m which means 1 Day = 24 hours + 2 hours + 10 min
Hope i clear my point.
Thanks for any help.
Anil,
Bqased on the comments above, I’d suggest saving a DateTime as the Departutre time (UTC) and then saving the minutes as an integer column. You can then calculate the offset as required. Below is a little console app to demonstrate the timespan usage, based on your example:
this produces a result of : 1:2:10 (1 day, 2 hours and 10 minutes).
this should work well for you when adding to your initial Departure time, i.e.:
Hope this helps.