DateCompare
Compares the difference between two dates - returning 0 if equal, -1 if date2 is less than date1 and 1 if the inverse
Method Signature
DateCompare(date1=[any], date2=[any], datepart=[string])
Arguments
Argument
Type
Required
Description
Default
date1
any
true
The reference date object
date2
any
true
The date which to compare against date1
datepart
string
false
Examples
Compare Two Dates by Year
dateCompare( "12/30/2015", "12/02/2015", "yyyy" );
Result: 0
Compare Two Dates by Day
Returns 1 because date1 is greater than date 2
dateCompare( "12/30/2015", "12/02/2015", "d" );
Result: 1
Member function example
d1 = createDate( "2024", "01", "01" );
d2 = createDate( "2024", "02", "14" );
d1.compare( d2 );
Result: -1
Additional Examples
writeOutput( dateCompare( now(), "11/10/1992" ) & " (Date1 is later than date2)<br>" );
writeOutput( dateCompare( "11/10/1992", "11/10/1992" ) & " (Date1 is equal to date2)<br>" );
writeOutput( dateCompare( "11/10/1992", now() ) & " Date1 is earlier than date2" );
d = createDate( year( now() ), month( now() ), day( now() ) );
d1 = "11/10/1992";
writeOutput( d.Compare( "11/10/1992" ) & " Date1 is later than date2<br>" );
0;
writeOutput( d.Compare( d ) & " (Date1 is equal to date2)<br>" );
writeOutput( d1.Compare( d ) & " Date1 is earlier than date2" );
Related
Last updated
Was this helpful?