devxlogo

Don’t use = operator on Date values

Date variables store values in floating point format, much like Double variables, with the integer part for dates and the fractional part for the time portion. Being floating point values, Data values may be subject to rounding problems, and for this reason you shouldn’t test two Date variables for equality using the “=” operator.

Instead, use the DateDiff function, or evaluate the difference between the two values and check that it’s less than a very small value, as in:

If Abs(Date1 - Date2) < 1E-10 Then    MsgBox "Same dates"End If

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Engineering Leaders Spot Weak Proposals

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.