Date Transformations
In addition to number transformations, Prisma Campaigns also offers the ability to manipulate dates. This includes formatting, adjusting and converting dates according to the needs of your communications or data integrations. As with numbers, date transformations do not alter the original value of the field, but rather generate a transformed representation for use in specific contexts.
Typical Use Cases
Date transformations are especially useful in two main contexts:
- In the presentation layer
- In the column mapping during data import or export
For each of these contexts, Prisma Campaigns offers a number of transformation functions that can be applied to date fields.
The
as_date()
function is used to convert a text string to a date, whileformat-date()
applies a specific format to it (such asyyyy-MM-dd
,MM/dd/yyyy
, etc.). Also,formal()
andFormal()
allow formatting dates in different languages. On the other hand,addDays()
allows adding or subtracting days to a date.
Date Transformations at the Presentation Layer
This is the simplest case and is commonly used to display dates in a specific format within a communication, such as on a landing page, an email, or in a funnel.
Usage examples:
<p>
Your next renewal date is
{{{customer.renewal-date:as_date():format-date("yyyy-MM-dd")}}
</p>
=>Your next renewal date is 2024-11-18.
<p>
Your next renewal date is {{customer.renewal-date:as_date():formal("en")}}}
</p>
=>Your next renewal date is Monday, November 18, 2024.
<p>
Your next renewal date is {{{customer.renewal-date:as_date():Formal("en")}}
</p>
=> Your next renewal date is Monday, November 18, 2024.
<!-- Adding a grace period to the renewal date -->
<p>
Your next renewal date is
{{{customer.renewal-date:as_date():addDays(14):formal("en")}}}
</p>
=> Your next renewal date is Monday, December 2, 2024.
The image below shows what the result would look like on a landing page after applying the date transformations:
Date Transformations During Column Mapping
Transformations are also applied in the context of data synchronization, such as importing CSV files or exporting customer data. In this case, dates can be parsed, converted to a standard format or replaced if the original value is null.
Conversion During Import
When importing data from a CSV file into Prisma Campaigns, it is common for the date formats in the file to not match the format required by the data model configured in the application. For example:
- In the data model, the field
renewal-date
is defined as aDate
type and uses the standard ISO formatYYYY-MM-dd
. - However, in the CSV file to be imported, the dates are formatted as
MM/dd/YYYY
. Additionally, some date values in the column may be empty.
In this case, the following transformation ensures that the imported data is adapted to the format expected by the Prisma Campaigns data model:
renewal-date:or("1900-01-01"):as_date():format-date("YYYY-MM-dd")
Where:
or("1900-01-01")
assigns the default date1900-01-01
if therenewal-date
field is empty.as_date()
converts the field —either the original value or the default assigned in the previous step— into a date.format-date("YYYY-MM-dd")
transforms the date into the ISO standard format.
Thus, if the CSV file contains the following dates in the renewal-date
column:
customer-id | renewal-date |
---|---|
ISA-H900 | 01/15/2024 |
WALLIS-H901 | 11/08/2024 |
YOLA-H902 | |
JOHN-H903 | 03/20/2025 |
After applying the transformation, the imported data will look as follows:
customer-id | renewal-date |
---|---|
ISA-H900 | 2024-01-15 |
WALLIS-H901 | 2024-11-08 |
YOLA-H902 | 1900-01-01 |
JOHN-H903 | 2025-03-20 |
This functionality allows the imported data to align with the platform’s expected format, even if the source data does not initially meet the required formatting specifications.
Conversion During Export
When exporting data, the Prisma field format can be transformed to meet specific output requirements:
renewal-date:or("1900-01-01"):as_date():format-date("yyyy-MM-dd")
As shown in the image below, the renewal-date
will be displayed as 2024-11-18
in the exported CSV file for the customer where the field was not empty. For the rest the default date 1900-01-01
is assigned.
Related Articles
On this page