GlideDateTime - compareTo(Object dateTime)

Compares two date and time objects to determine whether one occurs before the other or if they are equivalent.

Table 1. Parameters
Name Type Description
dateTime Object Date time in a GlideDateTime object
Table 2. Returns
Type Description
Number
  • 0 = Dates are equal
  • 1 = Initial date is before the compare date
  • -1 = Initial date is after the compare date

Scoped equivalent

To use the compareTo() method in a scoped application, use the corresponding scoped method: Scoped GlideDateTime - compareTo(Object o).

var initDate = new GlideDateTime("2011-08-01 12:00:00");
var compDate1 = new GlideDateTime("2011-08-01 12:00:00");
var compDate2 = new GlideDateTime("2011-07-31 12:00:00");
var compDate3 = new GlideDateTime("2011-08-04 16:00:00");
 
gs.info(initDate.compareTo(compDate1)); // Equals
gs.info(initDate.compareTo(compDate2)); // Earlier than
gs.info(initDate.compareTo(compDate3)); // Later than