I would to check if a date fall between two limites.
StartDate = '2018-01-01 11:10:00' EndDate = '2018-02-01 14:00:30'
- CheckDate1 = '2018-01-01 11:09:00' -> FAIL
- CheckDate2 = '2018-01-01 11:10:01' -> OK
- CheckDate3 = '2018-01-01 14:00:31' -> FAIL
- CheckDate4 = '2018-01-01 14:00:29' -> OK
I tried the following check:
CheckDateX >= StartDate && CheckDateX <= EndDate;
This doesn't seems to take the seconds into account. So I tried the following check:
CheckDateX.Ticks >= StartDate.Ticks && CheckDateX.Ticks <= EndDate.Ticks;
But the result is also wrong. Is there a correct and elegant way to compare to DateTime in C#?