compareDates


Compares two dates and returns the result as an integer.

Parameters


Combine the parameters as a JSON structure as input.

Parameter

Mandatory/Optional

Data Type

Description

startDate

Mandatory

String

The start date and time.

endDate

Mandatory

String

The end date and time.

startDatePattern

Mandatory

String

The format for the startDate parameter, for example: yyyyMMdd HH:mm:ss.SSS

endDatePattern

Mandatory

String

The format for the endDate parameter, for example: yyyyMMdd HH:mm:ss.SSS

Note

If startDate is 2021-03-10 (startDatePattern is yyyy-MM-dd) and endDate is 2021-03-10 11:11:55:111 (endDatePattern is yyyy-MM-dd HH:mm:ss:SSS), this function will assume that the start date is earlier than the end date and return a -1 value. For more information on the return values, see Return Values.

Return Values

Value

Data Type

Description

Value

Number

Checks whether startDate is before, the same with, or after the endDate.
  • -1:startDate is before endDate

  • 0:startDate is the same as endDate

  • +1:startDate is after endDate

Samples

var difference = tools.DateUtil.compareDates({"startDate" : "2021-03-10", "endDate" : "2021-03-10 11:11:55:111", "startDatePattern" : "yyyy-MM-dd", "endDatePattern" : "yyyy-MM-dd HH:mm:ss:SSS"});
return tools.resultBuilder.build(true, JSON.stringify(difference))


Output

-1