- 1 Minute to read
- Print
- DarkLight
ecm:addInterval
- 1 Minute to read
- Print
- DarkLight
The function ecm:addInterval adds (or subtracts) an interval of time to the specified date. The value returned is a date data type.
Example
A message is sent to all customers who made a purchase in the last five days. The message contains a list of the products the customer purchased during that time.
All customer purchases are saved in a related data set Purchases. The related data set is linked to the attribute Client_ID. The client ID saved in the attribute is identical to the key of the related data set. Since customers can make multiple purchases, the related data set is not unique.
The ecm:addInterval function returns the value of today's date minus five days:
ecx:formatDate(ecm:addInterval(date.today, '-5d'),'yyyy-MM-dd',ecm:timeZone('Europe/London'),'',false
The value returned by this function is then used as a parameter in the ecx:filter function, which returns all entries for purchases made in the last five days. Since the related data set is not unique, a ForEach loop inserts the data into the message. The entire expression, set inside the ForEach loop, is constructed as follows:
<%ForEach var="count" items="${ecx:filter(ecx:related('Purchases', user.CustomAttribute['client_ID']), ['Date'], '>=', ecx:formatDate(ecm:addInterval(date.today, '-5d'),'yyyy-MM-dd',ecm:timeZone('Europe/London'),'',false))}"%> <%${count.Article}%> <%/ForEach%>
Structure
ecm:addInterval(date, string)
Parameters
Parameter | Description |
---|---|
date | Specifies the target reference date. To use the current date as the reference, enter date.Today. |
string | Specifies the interval to add to or subtract from the target date. The string pattern is (+|-)xxYxxMxxWxxdxxhxxmxx, where xx stands for a number. The letters identify the preceding number as:
The plus sign (+) adds the specified interval and the minus sign (-) subtracts the specified interval from the date parameter. |
The value used as the date parameter must include the interval specified by the string parameter. For example, to subtract 48 hours from the target date, the value used as the date parameter must include the hour