There is no point to parse them to DateTime
since they are time interval. TimeSpan
would be better choice since it is exactly what this for.
If Mintes
is typo and your values are always the same standard format, you can easily split them with white space and then parse to TimeSpan
.
For example;
var BreakOut= "10:15 Minutes";
var BreakIn = "10:30 Minutes";
BreakOut = BreakOut.Split(new string[]{" "},
StringSplitOptions.RemoveEmptyEntries)[0];
BreakIn = BreakIn.Split(new string[] { " " },
StringSplitOptions.RemoveEmptyEntries)[0];
var ts1 = TimeSpan.Parse(BreakOut, CultureInfo.InvariantCulture);
var ts2 = TimeSpan.Parse(BreakIn, CultureInfo.InvariantCulture);
var difference = ts2 - ts1;
Console.WriteLine("{0} minutes", difference.TotalMinutes); // 15 Minutes
Here a demonstration
.