473,320 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

DateTime.Compare question

string dateTime = "5/28/2008";

DateTime.Compare(DateTime.Now,DateTime.Now) // returns 0
DateTime.Compare(DateTime.Now,DateTime.Parse(dateT ime)) // returns 1

I need to compare 2 dates, using the second format, and I
dont understand why it isnt returning 0

Thank you
Jun 27 '08 #1
3 2709
SandpointGuy <Sa**********@discussions.microsoft.comwrote:
string dateTime = "5/28/2008";

DateTime.Compare(DateTime.Now,DateTime.Now) // returns 0
DateTime.Compare(DateTime.Now,DateTime.Parse(dateT ime)) // returns 1

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.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #2
On May 28, 2:58*pm, SandpointGuy
<Sandpoint...@discussions.microsoft.comwrote:
string dateTime = "5/28/2008";

DateTime.Compare(DateTime.Now,DateTime.Now) // returns 0
DateTime.Compare(DateTime.Now,DateTime.Parse(dateT ime)) // returns 1

I need to compare 2 dates, using the second format, and I
dont understand why it isnt returning 0

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
Jun 27 '08 #3
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.comwrote:
string dateTime = "5/28/2008";

DateTime.Compare(DateTime.Now,DateTime.Now) // returns 0
DateTime.Compare(DateTime.Now,DateTime.Parse(dateT ime)) // returns 1

I need to compare 2 dates, using the second format, and I
dont understand why it isnt returning 0

Thank you
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sorisio, Chris | last post by:
Ladies and gentlemen, I've imported some data from a MySQL database into a Python dictionary. I'm attempting to tidy up the date fields, but I'm receiving a 'mx.DateTime.Error: cannot convert...
2
by: SenthilVel | last post by:
HI how to get the differences between 2 given dates?? supposse if i ahve 2 dates , DATEa, and current datetime. how can i find if the DATEa is less then 3 hrs from the current datetime ???...
12
by: conckrish | last post by:
Hi all.. Can anyone tell me how to compare datetime objects?I ve three objects namely Current date,start date and end date.. I need to check the current date with Start date and end date....Plz...
3
by: Tim Cowan | last post by:
Hi, In my application I need to compare whether one time is greater than another. What I am doing right now is taking the current datetime, formatting as string without the time element, and...
4
by: Harold Crump | last post by:
Greetings, This is not strictly a ASP.NET question, but I am hoping someone can help. I have an ASP.NET web app that used the DateTime.Parse and Compare methods a lot. As expected, the...
3
by: Mark | last post by:
I'd like to compare two datetime values in milliseconds. The datetime.compare method appears to show only seconds. Milliseconds of a datetime are available as a property of each datetime, but I...
2
by: PurpleServerMonkey | last post by:
Hopefully a simple DateTime problem. I've got a windows service created in C# on .Net Framework 2.0, the service uses a system timer to fire an event every second and compare that against a...
3
by: Matt Brown - identify | last post by:
Hello, I'm trying to figure out a method to look up by a range of dates, entries in a database. The format of the date in the database is "M\D \yyyy HH:MM:SS". What i need to do is take the...
3
by: ChrisB | last post by:
Hello, I was wondering what the easiest way is to compare two DateTime objects and not have the time components be included in the comparision. For, example, if time1 = 10/01/07 9:00 am, and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.