string dateTime = "5/28/2008";
DateTime.Compare(DateTime.Now,DateTime.Now) // returns 0
DateTime.Compare(DateTime.Now,DateTime.Parse(dateTime)) // returns 1
I need to compare 2 dates, using the second format, and I
dont understand why it isnt returning 0
Thank you
Jon Skeet [C# MVP] - 28 May 2008 20:17 GMT
> string dateTime = "5/28/2008";
>
[quoted text clipped - 3 lines]
> I need to compare 2 dates, using the second format, and I
> dont understand why it isnt returning 0
Because it's not midnight right now. If you only want to compare the
date components, use DateTime.Today.

Signature
Jon Skeet - <skeet@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Ignacio Machin ( .NET/ C# MVP ) - 28 May 2008 21:44 GMT
On May 28, 2:58 pm, SandpointGuy
<Sandpoint...@discussions.microsoft.com> wrote:
> string dateTime = "5/28/2008";
>
[quoted text clipped - 5 lines]
>
> Thank you
Hi,
DateTme.Now include a time component.
Also it might be possible that the first line (using Now both times)
give also <>1, depending of how fast both evaluations are performed
Duggi - 29 May 2008 07:53 GMT
DateTime.Now inclides current time also. In the string you did not
give the time, means it takes as midnight 12:00. So its quite
meaningful to get 1 returned.
instead try the following
string dateTime = "5/29/2008";
DateTime.Compare(DateTime.Today, DateTime.Parse(dateTime)); //returns
0
Hope this should solve the issue that you are facing.
Thanks
Cnu
On May 28, 11:58 pm, SandpointGuy
<Sandpoint...@discussions.microsoft.com> wrote:
> string dateTime = "5/28/2008";
>
[quoted text clipped - 5 lines]
>
> Thank you