private void TimeCalcu(DateTime start, DateTime end) { var DayDifference = end.DayOfYear.CompareTo(start.DayOfYear); if (DayDifference == 0) // Today { SubSpan = StartAndEnd(start.TimeOfDay, end.TimeOfDay); var timeStop = end.TimeOfDay.Duration().Subtract(start.TimeOfDay.Duration()); TotalStop = timeStop - TimeSpan.FromMinutes(SubSpan); } else if (DayDifference == 1) // More Day { var numberDaysStop = end.Subtract(start).Days; if (numberDaysStop == 1) // One Day { SubSpan = StartAndEnd(start.TimeOfDay.Duration(), Closing.Duration()); var totalStop1 = Closing.Duration().Subtract(start.TimeOfDay.Duration()); SubSpan += StartAndEnd(Opening.Duration(), end.TimeOfDay.Duration()); var totalStop2 = end.TimeOfDay.Duration().Subtract(Opening.Duration()); TotalStop = (totalStop2 + totalStop1) - TimeSpan.FromMinutes(SubSpan); } else if (numberDaysStop > 1) // More Day { SubSpan = StartAndEnd(start.TimeOfDay.Duration(), Closing.Duration()); var totalStop1 = Closing.Duration().Subtract(start.TimeOfDay.Duration()); SubSpan += StartAndEnd(Opening.Duration(), end.TimeOfDay.Duration()); var totalStop2 = end.TimeOfDay.Duration().Subtract(Opening.Duration()); var numDayStop = TimeSpan.FromMinutes(numberDaysStop * 600); TotalStop = (totalStop2 + totalStop1 + numDayStop) - TimeSpan.FromMinutes(SubSpan); } } var TotalStopMin = TotalStop.TotalMinutes; textBox1.Text = $"{TotalStopMin}"; }