473,473 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

datetime compare

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
Oct 1 '07 #1
3 6191
On Oct 1, 11:42 am, "ChrisB" <pleasereplytogr...@thanks.comwrote:
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
Hi Chris,
I would just compare the .Date properties:

DateTime dt1 = new DateTime(2007, 10, 1, 10, 0, 0);
DateTime dt2 = new DateTime(2007, 10, 1, 9, 0, 0);
TimeSpan ts = dt1.Date - dt2.Date;
bool sameDate = (ts == TimeSpan.Zero);

John

Oct 1 '07 #2
Chris,

You would use time1.Date.CompareTo(time2.Date) == 0
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ChrisB" <pl****************@thanks.comwrote in message
news:OB**************@TK2MSFTNGP04.phx.gbl...
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


Oct 1 '07 #3
Thanks, Nicholas. That did the job.

Chris

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:uX**************@TK2MSFTNGP03.phx.gbl...
Chris,

You would use time1.Date.CompareTo(time2.Date) == 0
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ChrisB" <pl****************@thanks.comwrote in message
news:OB**************@TK2MSFTNGP04.phx.gbl...
>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



Oct 2 '07 #4

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

Similar topics

0
by: PAUL MENARD | last post by:
--0-930715088-1061086093=:22602 Content-Type: text/plain; charset=us-ascii Hello All, I'm having trouble understanding the MySQL docs on how to subtract two DATETIME values. I have two tables...
3
by: Dirk Reske | last post by:
Hello, I have two dates. How can I check if the second date is the day after the first date? thx -- ---------------------------------------------------- I'm from Germany, so excuse my...
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 ???...
5
by: Tom | last post by:
It appears that you can't compare two dates in DotNet. You must use ToString and compare the strings. Is that the only reliable way? Try this: Dim dteOne As Date =...
4
by: Mika M | last post by:
I need to compare two DateTime variables named as t1 and t2 using VB.NET 2003. If t1 is any earlier time as t2, only then program should do something like... If (t1 < t2) Then...
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...
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: =?Utf-8?B?U2FuZHBvaW50R3V5?= | last post by:
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
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.