DateTime.Compare is always returning -1

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)
 
J

Jon Skeet [C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top