Home All Groups Group Topic Archive Search About

DateTime.Compare is always returning -1

Author
6 Oct 2005 5:41 PM
Arne
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)

Author
6 Oct 2005 9:32 PM
Jon Skeet [C# MVP]
Arne <A***@discussions.microsoft.com> wrote:
> 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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Author
7 Oct 2005 12:09 AM
Arne
I think I got it working now. I seems to have used the wrong year when testing.


Show quote
"Jon Skeet [C# MVP]" wrote:

> Arne <A***@discussions.microsoft.com> wrote:
> > 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.
>
> --
> Jon Skeet - <sk***@pobox.com>
> http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too
>

AddThis Social Bookmark Button