AddDuration is a datetime service, which takes in a StartDate (and time) and performs math on that value to find the requested DateTime. You can add (or subtract by adding a negative value) Years, Months, Days, Hours, Minutes, or Seconds. If only a date format is passed in with not time, 00:00:00 time is assumed (midnight).
The AddDuration service is smart and can take in a wide variety of StartDate formats (for example, JDEDate not accepted), however if the service does not receive the expected input StartDate, instead of throwing an exception, it just returns the current date time without performing any of the duration operations. Keep this in mind in your processes as you will not be able to depend on an exception to know it is failing.
Although it could be done, it is not good development practice to set your AddDuration service up so that when AddDuration “fails” and returns the current datetime instead of performing the expected operation, that default value of the current date time is used. This is because the error handling on this process could change in the future and cause unexpected results in your process.
|Separator||The Default value is /. This can be changed to another character, like a dash (-) for example. Some of the output dates use this separator value. Valid Separator values: "/", ":", "-"|
|StartDate||This is the starting point from where the calculation is performed. A StartDate is always needed, even if you would like to use the current date/time as the start date. This takes both Date and time. If a time is not entered, 000000 is assumed (midnight).|
|Duration||This takes a numeric value, though it could be positive or negative. This is the amount of the duration type you would like to add (or subtract if using a negative number). For instance, if Duration type is set to Minutes, this value could be 10 and the service will add 10 minutes.|
|DayOfMonth||Ex: 17. This is the 17th day of the month.|
|DayOfYear||Ex: 351. This is the 351st day of the year.|
|EPLongDate||The time is in a 24 hour format. Ex: 2018/12/17 12:40:34. 2018/12/17 13:04:22.|
|Hour||Hour portion of the time. This is a 24 hour format. Ex: 12. This is the 12th hour. If it were 1pm, the hour would be 13.|
|JDETime||JDE Time format. the format is HH-MM-SS. Ex: 124034. This is 12:40 and 34 seconds. This is a 24 hour format. 1:05pm would be 130500|
|LongDate||Ex: Monday, December 17, 2018.|
|Minute||Minute portion of the time. Ex: 40. This is the 40th minute of the hour.|
|MMDDYYYY||The separators used are determined by the separator value passed in the input. Ex: 12/17/2018.|
|Second||Second portion of the time. Ex: 34. This is the 34th second of the minute.|
|Year||Year portion of the date. Ex: 2018.|
|YYYYMMDD||The separators used are determined by the separator value passed in the input. Ex: 2018/12/17.|
AddDuration Use Examples
Basic Use Example
In this example, there is a table which stores a CreatedOn column. This table fills up quickly, so every so often, we would like to clear out the old records from this table. However, we want to only delete records that are 3 minutes old or older. To do so, we compare the column to the datetime from three minutes ago and delete the old ones.
To do so, we must first find the current datetime so there is a value we can enter into the StartDate of the AddDuration service. The AddDuration service can take the StartDate in a large variety of formats, which makes it a great tool. This also means, we don’t have to care too much about what format we take from GetCurrentDateTime and pass into AddDuration.
From the output of AddDuration, we get the string which we will compare to the values in the table. This is the output from AddDuration. Notice the difference in the two outputs. One of them uses dashes because the “Separator” input was changed to “-”.