Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare just the date part and not the time of two Dates?

I want to compare just the date part (and Not the time) of two VB.NET Date objects. Is there a way to do that?

like image 985
Ylva D Avatar asked Mar 06 '09 13:03

Ylva D


People also ask

How do you compare only dates?

CompareTo(DateOnly) Compares the value of this instance to a specified DateOnly value and returns an integer that indicates whether this instance is earlier than, the same as, or later than the specified DateTime value.

How do I compare dates in Excel without time?

Often you may want to compare two dates in Excel while ignoring the time values associated with the dates. Fortunately you can use the INT() function in Excel to extract just the date from a datetime value, which allows you to easily compare dates while ignoring the time.


1 Answers

Just take the date part of each via the Date property and compare the two:

date1.Date.CompareTo(date2.Date) 

Or:

If date1.Date < date2.Date Then 
like image 55
Jon Skeet Avatar answered Oct 26 '22 08:10

Jon Skeet