|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DateTime.Compare is always returning -1DateTime.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 <A***@discussions.microsoft.com> wrote:
> DateTime.Compare is always returning -1. What am I doing wrong? Hmm - works for me, even if I change the 10/5 to 5/10 (I don't know > > 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) 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 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 > |
|||||||||||||||||||||||