473,804 Members | 2,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DateTime.Compar e question

string dateTime = "5/28/2008";

DateTime.Compar e(DateTime.Now, DateTime.Now) // returns 0
DateTime.Compar e(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
Jun 27 '08 #1
3 2744
SandpointGuy <Sa**********@d iscussions.micr osoft.comwrote:
string dateTime = "5/28/2008";

DateTime.Compar e(DateTime.Now, DateTime.Now) // returns 0
DateTime.Compar e(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
Because it's not midnight right now. If you only want to compare the
date components, use DateTime.Today.

--
Jon Skeet - <sk***@pobox.co m>
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...@d iscussions.micr osoft.comwrote:
string dateTime = "5/28/2008";

DateTime.Compar e(DateTime.Now, DateTime.Now) // returns 0
DateTime.Compar e(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
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.Compar e(DateTime.Toda y, 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...@d iscussions.micr osoft.comwrote:
string dateTime = "5/28/2008";

DateTime.Compar e(DateTime.Now, DateTime.Now) // returns 0
DateTime.Compar e(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
Jun 27 '08 #4

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

Similar topics

1
3250
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 value to a time value' error. It's related to glibc returning an error to a pre-1970 date, I think. My question: /how/ do I go through the Python direction I've created to remove the pre-1970 date objects? Ideally, I would be able to iterate...
2
3139
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
61223
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 tell me how to compare ??? Thanx.. Krish
3
2490
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 then appending the time I want to the date and converting to date. DateTime dOpen = System.Convert.ToDateTime(now.Date.ToString("MMM dd, yyyy") + " " + storeOpen.Hour + ":" + storeOpen.Minute);
4
3045
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 Regional Settings/Culture on the server (Windows Server 2003), affects the behaviour of those DateTime functions (date
3
28515
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 am assuming there is an easier way than comparing the milliseconds, seconds, minutes, hours, days, etc, individually to generate the difference. Thanks in advance. Mark
2
3116
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 known time to fire off a worker thread. All the DateTime objects are using local time as the services are local to the server. DateTime runAt = DateTime.Parse("4/24/2007 2:30:00 PM"); System.Timers.Timer _timer = new System.Timers.Timer();
3
2234
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 dates that are in the database (formatted as above), isolate the date (which is in short format) and compare it to the short formatted date in a datetimepicker.
3
6226
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 time2 = 10/1/07 10:00 am, time1.CompareTo(time2) == 0 should evaluate to true. Thanks, Chris
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10352
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7642
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.