Forget about the time when comparing dates in SSJS

I needed to compare two dates in SSJS and determine if a date was on or before tomorrow. Sounds pretty easy but it took me a while to figure this out. The hard part was that I needed to remove the time part, I only wanted to compare the dates.

As always (or most of the times) the solution turned out to be pretty simple and involved using the @Date() function. So if you ever need to do the same, just use the following (note that all dates are java.util.Date instances, not NotesDateTime objects).

//set an input date
//for this example the date is set to June 1st, 2011
//remember: in Java(script), a month is represented by an integer from 0 to 11;
//0 is January, 1 is February, and so forth; thus 11 is December
var inputDate = new Date();
inputDate.setFullYear(2011, 5, 1);

//set target date
//you can also use @Date( @Adjust(@Now(), 0,0,1,0,0,0) )
var targetDate = @Date( @Tomorrow() );

//check if the specified date is before or on the target date
var result = (@Date(inputDate).before( targetDate ) || 
    @Date(inputDate).equals(targetDate));