Is there a way to compare Date objects ignoring time?

Is there a way to compare two dates (including time), ignoring time?

I have 1/1/2009 8:00 and 1/1/2009 9:00, and I just want to know if he is on the same day without caring about what time he is.

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

+3
source share
2 answers

Yes, you can use the .Date property of the Date object that 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
+11
source
dim Date1 = firstdate.ToShortDateString
dim Date2 = seconddate.ToShortDateString
if (Date1 = Date2) then
   'Dates Match!
   return true;
else return false
0
source

Source: https://habr.com/ru/post/1710726/


All Articles