In some cynerio we need difference between two times. For ex. In corporate sector employees in time and out time we mensioned then we need how many hours the employee works in the office. In this situation we need differences between two timings.
string startTime = “7:00 AM”;
string endTime = “2:00 PM”;
TimeSpan duration = DateTime.Parse(endTime).Subtract(DateTime.Parse(startTime));
it will generate the output as 7 hours.