none
difference in time RRS feed

  • Question

  • i need to get difference of END TIME AND START TIME of next line as a output, can you please help me how to get?

    START TIME     END TIME

    9:06:33            21:27:00

    10:46:00          10:50:00

    10:46:00           13:04:00


    Friday, May 17, 2019 8:40 AM

All replies

  • You can calculate it using TimeSpan:

    public static void Main()
            {
                var result1 = GetDiferenceBetweenTimes(new TimeSpan(9, 06, 33), new TimeSpan(21, 27, 0)); // Diff: 12:20:27
                var result2 = GetDiferenceBetweenTimes(new TimeSpan(10, 46, 0), new TimeSpan(10, 50, 0)); // Diff: 00:04:00
                var result3 = GetDiferenceBetweenTimes(new TimeSpan(10, 46, 0), new TimeSpan(13, 4, 0)); // Diff: 02:18:00
            }
    
            public static TimeSpan GetDiferenceBetweenTimes(TimeSpan start, TimeSpan end)
            {
                return end - start;
            }

    If you have text as Time, you can parse text to TimeSpan:

    var myTime = TimeSpan.Parse("14:44:32");

    • Proposed as answer by Danilo Peres Saturday, May 18, 2019 9:15 AM
    Saturday, May 18, 2019 9:15 AM