Found what I needed right after I posted (of course). Thank you for the help. I wasn't understanding TimeSpan and didn't realize I could simply tack .TotalHours to the end of my TimeSpan variable to get what I needed.
Please explain like I'm 5 years old.
I have two DateTimePicker objects with a custom format of HH:mm so that only military time is entered. Date is irrelevant. One picker is for the start time and the other picker is for the end time.
I need to be able to subtract the start time from the end time in order to get a total length of time in hours between them.
I then need this length of time converted to an integer I suppose? So that I can later use an if statement to see if it is equal to or above a certain number.
I know that DateTime can use the > < and other operators, so that's what I'd like to use.
However when I try to create a variable like so:
var timeLength = endTime.Value - startTime.Value;
It tells me its a TimeSpan variable.
I tried to make a DateTime variable so I could use the > < and other operators later:
DateTime timeLength = endTime.Value - startTime.Value;
And I get red squigglies
"Cannot implicitly convert type 'System.TimeSpan' to 'System.DateTime'
Well okay VS, I don't want a TimeSpan variable. At least I don't think I do?
Anyway, obviously this means I can't later user the shiftLength
variable to compare to things, so that's not working.
I tried to do it straight in my if statement:
if (endTime.Value - startTime.Value <= 12)
Operator '<=' cannot be applied to operands of type 'TimeSpan' and 'int'
Alright. Fine. So.
1) Why is it calling this a TimeSpan variable. I'm trying to look into TimeSpan properties and it's confusing the heck out of me. Do I need to use TimeSpan to accomplish what I'm trying to do? and if not..
2) What's the simplest way to subtract my DateTimePicker endTime.Value from my startTime.Value to be able to compare it to an integer with < > = operators?