Sample code using DateTime.TimeOfDay
DateTime timeNow = DateTime.Now; DateTime fromTime = new DateTime(2015, 11, 14, 08, 00, 00); DateTime toTime = new DateTime(2015, 11, 14, 14, 30, 00); if (TimeSpan.Compare(timeNow.TimeOfDay, fromTime.TimeOfDay) == 1 && TimeSpan.Compare(timeNow.TimeOfDay, toTime.TimeOfDay) == -1) { }
In the above code, if the timeNow variable is between 08:00:00 and 14:30:00, then the condition will become true.
1 represents time1 > time2 0 represents time1 = time2 -1 represents time1 < time2
source share