DateTime.Value.CompareTo in c#

  • From: "Andy B" <a_borka@xxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 24 Oct 2007 19:51:15 -0400

Anybody know why this code doesnt work? Put inside the Tick event of a
timer. The Time.Value is the Value from a DateTimePicker called Time. It is
supposed to show a MessageBox when the time/date on the DateTimePicker
matches the current system time exactly... Any idea how this is supposed to
work? The docs on DateTime.CompareTo(DateTime Date) said that if the result
of CompareTo == 0, then the 2 dates match. It seems broke. I ran a test on
it: Put a textBox on the form and change the MessageBox line to:
textBox1.Text=DateTime.Now.CompareTo(Time.Value).ToString(); Now run the
program. Change the DateTimePicker to a date earlier than the system time,
and the value -1 shows up in the box (expected). Change the picker to a time
later than the system time, and you get 1 in the box (expected). Wait until
the system time catches up with the picker... no 0? It just goes from -1 to
1... *confused*...
<original code>
if (DateTime.Now.CompareTo(Time.Value) == 0)

MessageBox.Show("times up");

</original code>


<test code>


</test code>



Other related posts: