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.
Function Overview
Function | Description |
|---|---|
ecm:equal | Determines whether two specified dates are equal. |
ecm:greater | Determines whether a specified date is greater than a reference date. |
ecm:greaterEqual | Determines whether a specified date is equal to or greater than a reference date. |
ecm:less | Determines whether a specified date is less than a reference date. |
ecm:lessEqual | Determines whether a specified date is equal to or less than a reference date. |
ecm:notEqual | Determines whether a specified date is not equal to a reference date. |
ecm:age | Returns the number of years between two dates. |
ecm:between | Determines whether a specified date is between a start and an end date. |
ecx:durationBetween | Calculates the difference between two dates in a specified unit. |
ecx:isInTimePeriod | 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 is used to send a thank you message to group members on the anniversary of the date they signed up for a newsletter. This date is stored in the custom attribute WelcomeDate.
The function ecm:trunc is used to reset the time component for both the current date and the attribute value to zero. It is then possible to use the function ecm:equal to define the selection criteria because the time component is negated. 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 |
|---|---|
date | Specifies the target date. |
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
Personalization is displayed to recipients under 30 years old when a message is sent. The message is scheduled for sendout on April 5, 2011.
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-05-04', ecm:timeZone('Europe/Berlin')))}"%>Text<%/InsertIf%>Structure
ecm:equal(date, date)
Parameters
Parameter | Description |
|---|---|
date | Specifies the target date. |
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
Personalization is displayed to recipients under 30 years old when a message is sent. The message is scheduled for sendout on April 5, 2011.
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-05-04', ecm:timeZone('Europe/Berlin')))}"%>Text<%/InsertIf%>Structure
ecm:greaterEqual(date, date)
Parameters
Parameter | Description |
|---|---|
date | Specifies the target date. |
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
Personalization is displayed to recipients who are at least 55 years old when a message is sent. The message is scheduled for sendout on April 5, 2011.
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-05-04', ecm:timeZone('Europe/Berlin')))}"%>Text<%/InsertIf%>Structure
ecm:less(date, date)
Parameters
Parameter | Description |
|---|---|
date | Specifies the target date. |
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
Personalization is displayed to recipients who are at least 55 years old when a message is sent. The message is scheduled for sendout on April 5, 2011.
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-05-04', ecm:timeZone('Europe/Berlin')))}"%>Text<%/InsertIf%>Structure
ecm:lessEqual(date, date)
Parameters
Parameter | Description |
|---|---|
date | Specifies the target date. |
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
${ecm:notEqual(user.DateOfBirth, ecm:toDate('1986-01-01', ecm:timeZone('Europe/Berlin')))}Structure
ecm:notEqual(date, date)
Parameters
Parameter | Description |
|---|---|
date | Specifies the target date. |
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
A Personalization 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 |
|---|---|
date | Specifies the target date. |
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 18 years of age or older. The function ecm:between checks whether the date of birth stored as a user attribute is between today's date and the date 18 years in the past (using the additional function ecm:addInterval to subtract 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 |
|---|---|
date | Specifies the target date. |
date | The value used as a start date. |
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 |
|---|---|
date | The value used as a start date. |
date | The value used as an end date. |
string | 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 |
|---|---|
string | 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. |
string | The time zone used as local time. If no time zone is given, 'Europe/Berlin' will be used as default. |