These functions provide tools for comparing two date values. Many of these functions process and return the information as a Boolean value which can be used to create personalization rules or selection criteria.
Several examples use ecm:toDate to convert a string into a date. See Extract and Format Dates and Times.
Function Overview
Function | Description |
|---|---|
| Determines whether two specified dates are equal. |
| Determines whether a specified date is greater than a reference date. |
| Determines whether a specified date is equal to or greater than a reference date. |
| Determines whether a specified date is less than a reference date. |
| Determines whether a specified date is equal to or less than a reference date. |
| Determines whether a specified date is not equal to a reference date. |
| Returns the number of years between two dates. |
| Determines whether a specified date is between a start and an end date. |
| Calculates the difference between two dates in a specified unit. |
| Verifies whether the current time is within one of the periods given as a parameter. |
ecm:equal
The function ecm:equal determines whether two specified dates are equal. The comparison is exact to the millisecond. The value returned is a Boolean data type.
Example
A selection sends a welcome message to contacts on the day they signed up for a newsletter. The sign-up date is stored in the custom attribute WelcomeDate.
The function ecm:trunc resets the time component of both the current date and the attribute value to zero. The function ecm:equal can then compare the two dates, because the time component no longer affects the result. The expression is constructed as follows:
${ecm:equal(ecm:trunc(user.CustomAttribute['WelcomeDate'], 'time'), ecm:trunc(date.Today, 'time'))}Structure
ecm:equal(date, date)
Parameters
Parameter | Description |
|---|---|
| Specifies the target date. |
| The date value used for the comparison. |
ecm:greater
The function ecm:greater determines whether a specified date is greater than a reference date. The comparison is exact to the millisecond. The value returned is a Boolean data type.
Example
The message is scheduled for sendout on April 5, 2011. Content is displayed to recipients born after April 5, 1981. These recipients are younger than 30 on the day of the sendout.
The content is inserted into the message with an InsertIf statement, which is constructed as follows:
<%InsertIf expression="${ecm:greater(user['DateOfBirth'], ecm:toDate('1981-04-05', ecm:timeZone('Europe/Berlin')))}"%>Text<%/InsertIf%>Structure
ecm:greater(date, date)
Parameters
Parameter | Description |
|---|---|
| Specifies the target date. |
| The date value used for the comparison. |
ecm:greaterEqual
The function ecm:greaterEqual determines whether a specified date is equal or greater than a reference date. The comparison is exact to the millisecond. The value returned is a Boolean data type.
Example
The message is scheduled for sendout on April 5, 2011. Content is displayed to recipients born on or after April 5, 1981. These recipients are younger than 30 or turn 30 on the day of the sendout.
The content is inserted into the message with an InsertIf statement, which is constructed as follows:
<%InsertIf expression="${ecm:greaterEqual(user['DateOfBirth'], ecm:toDate('1981-04-05', ecm:timeZone('Europe/Berlin')))}"%>Text<%/InsertIf%>Structure
ecm:greaterEqual(date, date)
Parameters
Parameter | Description |
|---|---|
| Specifies the target date. |
| The date value used for the comparison. |
ecm:less
The function ecm:less determines whether a specified date is less than a reference date. The comparison is exact to the millisecond. The value returned is a Boolean data type.
Example
The message is scheduled for sendout on April 5, 2011. Content is displayed to recipients born before April 5, 1956. These recipients are at least 55 years old on the day of the sendout. Recipients who turn 55 on that day are not included.
The content is inserted into the message with an InsertIf statement, which is constructed as follows:
<%InsertIf expression="${ecm:less(user['DateOfBirth'], ecm:toDate('1956-04-05', ecm:timeZone('Europe/Berlin')))}"%>Text<%/InsertIf%>Structure
ecm:less(date, date)
Parameters
Parameter | Description |
|---|---|
| Specifies the target date. |
| The date value used for the comparison. |
ecm:lessEqual
The function ecm:lessEqual determines whether a specified date is equal to or less than a reference date. The comparison is exact to the millisecond. The value returned is a Boolean data type.
Example
The message is scheduled for sendout on April 5, 2011. Content is displayed to recipients born on or before April 5, 1956. These recipients are at least 55 years old on the day of the sendout.
The content is inserted into the message with an InsertIf statement, which is constructed as follows:
<%InsertIf expression="${ecm:lessEqual(user['DateOfBirth'], ecm:toDate('1956-04-05', ecm:timeZone('Europe/Berlin')))}"%>Text<%/InsertIf%>Structure
ecm:lessEqual(date, date)
Parameters
Parameter | Description |
|---|---|
| Specifies the target date. |
| The date value used for the comparison. |
ecm:notEqual
The function ecm:notEqual determines whether a specified date is not equal to a reference date. The comparison includes millisecond values. The value returned is a Boolean data type.
Example
The following expression is true for all recipients who were not born on January 1, 1986:
${ecm:notEqual(user['DateOfBirth'], ecm:toDate('1986-01-01', ecm:timeZone('Europe/Berlin')))}Structure
ecm:notEqual(date, date)
Parameters
Parameter | Description |
|---|---|
| Specifies the target date. |
| The date value used for the comparison. |
ecm:age
The function ecm:age returns the number of years between two dates. The value returned is a long data type.
Example
Content is displayed to recipients who are 20 years or older at the time of message sendout. The function ecm:age compares the date of birth stored in a user attribute to the current date and returns a long number. This number is evaluated (using the mathematical operator greater than or equal) to return a Boolean value. If a Boolean value true is returned, the personalization is inserted into the message with an InsertIf statement. The InsertIf is constructed as follows:
<%InsertIf expression="${ecm:age(user['DateOfBirth'], date.Today) >= 20}"%>Text<%/InsertIf%>Structure
ecm:age(date, date)
Parameters
Parameter | Description |
|---|---|
| Specifies the target date. |
| The date value used for the comparison. |
ecm:between
The function ecm:between determines whether a specified date is between a start and an end date. The value returned is a Boolean data type.
Example
A selection verifies whether a recipient is younger than 18. The function ecm:between checks whether the date of birth stored as a user attribute is between the date 18 years in the past and today's date. The additional function ecm:addInterval subtracts 18 years from today's date. The function is constructed as follows:
${ecm:between(user['DateOfBirth'], ecm:addInterval(date.Today, '-18Y'), date.Today)}Structure
ecm:between(date, date, date)
Parameters
Parameter | Description |
|---|---|
| Specifies the target date. |
| The value used as a start date. |
| The value used as an end date. |
ecx:durationBetween
The function ecx:durationBetween calculates the difference between two dates in a specified unit. The value returned is a string data type.
Example
Calculate the number of days between a recipient's date of birth, which is stored as an attribute value, and the current date. The function is constructed as follows:
${ecx:durationBetween(user['DateOfBirth'], date.Today, 'days')}Structure
ecx:durationBetween(date, date, string)
Parameters
Parameter | Description |
|---|---|
| The value used as a start date. |
| The value used as an end date. |
| Specifies the unit of time used to calculate the duration. Possible units include 'seconds', 'minutes', 'hours', 'days', 'weeks', 'months' and 'years'. |
ecx:isInTimePeriod
The function ecx:isInTimePeriod verifies whether the current time is within one of the periods given as a parameter. The value returned is a Boolean data type.
Example
Message sendout is restricted to between 16:00 and 22:30 in the Europe/London time zone. The following function returns a true value if the current time is within a period of 6 hours and 30 minutes after 16:00:
${ecx:isInTimePeriod('16:00PT6H30M', 'Europe/London')}Structure
ecx:isInTimePeriod(string, string)
Parameters
Parameter | Description |
|---|---|
| Specifies the time period used for comparison. Must be given in ISO 8601 format and only contain the local time part, for example, 18:00PT8H is equal to a period of 8 hours starting at 18:00. |
| The time zone used as local time. If no time zone is given, 'Europe/Berlin' will be used as default. |