"I tried to test for every DateTimePicker. But I want to show only the smalles difference in the label. So I wrote a lot of if-querys in a timer to show only the smallest difference.
How can I write the if-querys for 7 DateTimePickers?"
Don't! :laugh: way, way too many combinations.
So...set up an array of TimeSpan values, and load it with the 7 DateTimePicker values minus the current dateTime:
DateTime now = DateTime.Now;
Timespan[] diffs = new TimeSpan[7];
diffs[0] = dateTimePicker1.Value - now;
diffs[1] = dateTimePicker2.Value - now;
diffs[2] = dateTimePicker3.Value - now;
diffs[3] = dateTimePicker4.Value - now;
diffs[4] = dateTimePicker5.Value - now;
diffs[5] = dateTimePicker6.Value - now;
diffs[6] = dateTimePicker7.Value - now;
Then use Array.Sort and you have the maximum and minimum easily available.
Array.Sort(diffs);
Timespan min = diffs[0];
Timespan max = diffs[6];
(Obviously, I wouldn't use "magic numbers" in the real world)
And only ever read the time once in a method: it changes outside your control, so even doing this:
DateTime now1 = DateTime.Now;
DateTime now2 = DateTime.Now;
if (now1 != now2) throw new ApplicationException("The time changed!");
Sometimes, you will get an exception, and sometimes you won't...and they can seem very different - different millenium if you do it at the wrong time! :laugh: