views:

193

answers:

2

Is there a way to compare two dates (which include time) ignoring the time?

I have a 1/1/2009 8:00am and 1/1/2009 9:00am and I just want to know if it is the same day, without any care to what time it is.

I know I can convert the date and compare the strings, but is there another way?

+7  A: 

Yes, you can use the .Date property of the Date object you are using.

dim originalDate as DateTime
originalDate = '(get your date for comparison)
if originalDate.Date = Datetime.now.date then
  'it happened today.
end if
Paul Farry
Well there you go, didn't know about that short cut!
Harry
Exactly what I was looking for, thanks
jvanderh
A: 
dim Date1 = firstdate.ToShortDateString
dim Date2 = seconddate.ToShortDateString
if (Date1 = Date2) then
   'Dates Match!
   return true;
else return false
Harry