Reputation: 6029
Having today's date for example: DateTime.Now
And 2 TimeSpan that represents two periods of time
DateTime mydate = DateTime.Now;
TimeSpan start = TimeSpan.Parse("14:00:00");
TimeSpan end = TimeSpan.Parse("15:00:00");
// TO DO:
How to check that mydate
time (TimeOfDay) is not between start
and end
range.
Basically check if the hours, minutes, seconds are between 14:00 and 15:00 or outside this range.
UPDATE:
The right condition is: mydate.TimeOfDay <= start || mydate.TimeOfDay >= end
Upvotes: 2
Views: 553
Reputation: 3013
Comparing them seems to work seams to work. TimeOfDay
is a TimeSpan
just like start
and end
Console.WriteLine(mydate.TimeOfDay <= start || mydate.TimeOfDay >= end);
Upvotes: 4