DateTime.Compare is always returning -1

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

DateTime.Compare is always returning -1. What am I doing wrong?

Dim today As DateTime = DateTime.Now
Dim temp As Integer
Dim endPeopleRegDate As DateTime
endPeopleRegDate = Convert.ToDateTime("10/5/2005 23:59:59")
temp = DateTime.Compare(today, EndPeopleRegDate)
today = Date.Now.AddMonths(1)
temp = DateTime.Compare(today, EndPeopleRegDate)
today = Date.Now.AddMonths(-5)
temp = DateTime.Compare(today, EndPeopleRegDate)
 
Arne said:
DateTime.Compare is always returning -1. What am I doing wrong?

Dim today As DateTime = DateTime.Now
Dim temp As Integer
Dim endPeopleRegDate As DateTime
endPeopleRegDate = Convert.ToDateTime("10/5/2005 23:59:59")
temp = DateTime.Compare(today, EndPeopleRegDate)
today = Date.Now.AddMonths(1)
temp = DateTime.Compare(today, EndPeopleRegDate)
today = Date.Now.AddMonths(-5)
temp = DateTime.Compare(today, EndPeopleRegDate)

Hmm - works for me, even if I change the 10/5 to 5/10 (I don't know
what culture you're in - 10/5/2005 means the 10th of May to me, but it
may mean the 5th of October to you).

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
Back
Top