The HotDocs Computation Archive
Get Extra Help

0011 - Comparing Dates

Description:

How to compare dates within a computation.


• Code •

Examples:

X = Y    Date X is the same as Date Y
X != Y   Date X is not the same as Date Y
X > Y    Date X is after Date Y
X <= Y   Date X is before or on Date Y

DateVarA >= DateVarB
DateVarA < DateVarB

DateVar = DATE OF( 4, 7, 1776 )
DateVar = DATE OF( 4, 7, YEAR OF( TODAY ) )
 
 
Example: Is DateVar before Christmas?

FALSE
IF DateVar < DATE OF( 25, 12, YEAR OF( TODAY ) )
   TRUE
END IF

• Explanation •

You can compare two dates using the normal comparison operators:

The X and Y values must both be HotDocs date values, not just strings containing dates. In other words, both dates must be either date variables or must use the DATE OF( day, month, year ) model, as shown in the examples above.

Because the year of the date we are comparing is not always fixed, it is sometimes good to use the YEAR OF( TODAY ) model. For example, to see if a date is on the first Independence Day, use DateVar = DATE OF( 4, 7, 1776 ). But to see if a date is on Independence day of this year, use DateVar = DATE OF( 4, 7, YEAR OF( TODAY ) ). This logic is used in the "Christmas" example, which looks at DateVar to see if it falls before Christmas of the current year. If it does, the computation returns TRUE. Otherwise it returns false.

 

• Contributors •

LegalCS