incrementDate


Increments a date/time by the specified date/time units.

Parameters


Combine the parameters as a JSON structure as input.

Parameter Mandatory/Optional Data Type Description
startDate Mandatory String The date/time for incrementation. The format for this parameter must match the format specified in startDatePattern.
startDatePattern Mandatory String The format for startDate, for example: yyyyMMdd HH:mm:ss.SSS
endDatePattern Optional String The format of the string returned after incrementation, for example: yyyyMMdd HH:mm:ss.SSS. If not specified or if blank spaces are specified as the value, the format specified in startDatePattern will be returned.
addYears Optional String The number of years to add to startDate. The range is from -2147483648 and 2147483647. If not specified, or the value is illegal or beyond this range, the default value will be 0.
addMonths Optional String The number of months to add to startDate. The range is from -2147483648 and 2147483647. If not specified, or the value is illegal or beyond this range, the default value will be 0.
addDays Optional String The number of days to add to startDate. The range is from -2147483648 and 2147483647. If not specified, or the value is illegal or beyond this range, the default value will be 0.
addHours Optional String The number of hours to add to startDate. The range is from -2147483648 and 2147483647. If not specified, or the value is illegal or beyond this range, the default value will be 0.
addMinutes Optional String The number of minutes to add to startDate. The range is from -2147483648 and 2147483647. If not specified, or the value is illegal or beyond this range, the default value will be 0.
addSeconds Optional String The number of seconds to add to startDate. The range is from -2147483648 and 2147483647. If not specified, or the value is illegal or beyond this range, the default value will be 0.
addMilliSeconds Optional String The number of milliseconds to add to startDate. The range is from -2147483648 and 2147483647. If not specified, or the value is illegal or beyond this range, the default value will be 0.
timezone Optional String The timezone for the returned date/time, such as GMT for Greenwich Mean Time. If not specified, GMT is used by default.
locale Optional String
Locale for the returned date/time. For example, if locale is EN (English), and pattern is EEE d MMM yyyy, the returned result will be Thu 2000-04-13 01:45:33. If not specified, EN is used by default. The locales currently supported are:
  • EN: English
  • CH: Chinese


Note

If startDate, startDatePattern, and endDatePattern are specified but the other optional incremental parameters are not specified, the startDate format will be converted from the startDatePattern to the endDatePattern format and returned as endDate.

Return Values

Value Data Type Description
endDate String The date/time in the format specified in endDatePattern after incrementing the date/time to startDate.

Samples

var format = tools.DateUtil.incrementDate({"startDate":"2021-04-13 10:23:55","startDatePattern":"yyyy-MM-dd hh:mm:ss","endDatePattern":"EEE yyyy-MM-dd hh:mm:ss","addYears":"1","addMonths":"1","addDays":"1","addHours":"1","addMinutes":"1","addSeconds":"1","addMilliSeconds":"111","timezone":"AGT","locale":"EN"});
return tools.resultBuilder.build(true, JSON.stringify(format));


Output

"Sat 2022-05-14 08:24:56"