i want to check the time that falls into two different date. assume that i need to check from 10:30pm from this day up to 7am of tomorrow.
TimeSpan NightShiftStart = new TimeSpan(22, 30, 0);//10:30pm
TimeSpan NightShiftEnd = new TimeSpan(7, 0, 0); //7am
and compare it
if ((now > NightShiftStart ) && (now < NightShiftEnd )){}
timespan wont work on this i also tried
DateTime t1 = DateTime.Today.AddHours(22);
DateTime t2 = DateTime.Today.AddDays(1).AddHours(7);
still no luck.
You can use the TimeOfDay property and use that instead. So your code should look like this
EDIT: While the above code is fine for what you asked, this way is a bit more generic and works for all kinds of shifts, as long as you know when they start and end:
Usually you should use >= or <= for comparing either ShiftStart or ShiftEnd as you want an exact time to also fall into one of your shifts.