Formatting and incrementing date fields in emails

When using a Sora date field within an email template, the default formatting will be in MM/DD/YY format. However, Sora offers several built-in functions for formatting and incrementing date fields.

Formatting Dates

  • You change a date fields format using the <code>formatDate<code> function. This function takes in two parameters, the date field and the desired format string, as shown in this example: <code>{{formatDate startDateField "YYYY-MM-DD"}}<code>
  • Note: the date argument should follow the same camel-casing format described in the note in the Conditional Content Blocks section.
  • Note that no end code is required (i.e. <code>{{/formatDate}}<code>) for formatting dates.

The following examples reference a Start date field (this can be replaced with any date field) which is set to 2/16/2022:

  • <code>{{formatDate startDateField "dddd"}}<code> = Wednesday
  • <code>{{formatDate startDateField "ddd"}}<code> = Wed
  • <code>{{formatDate startDateField "MMMM"}}<code> = February
  • <code>{{formatDate startDateField "MMM"}}<code> = Feb
  • <code>{{formatDate startDateField "YYYY"}}<code> = 2022
  • <code>{{formatDate startDateField "YY"}}<code> = 22
  • <code>{{formatDate startDateField "DD"}}<code> = 16
  • <code>{{formatDate startDateField "Do"}}<code> = 16th

Combining the above together, here are a couple of examples on date formatting:

  • <code>{{formatDate startDateField "dddd, MMMM Do"}}<code> = Wednesday, February 16th
  • <code>{{formatDate startDateField "dddd, MMMM DD"}}<code> = Wednesday, February 16

Adding incremental dates

Use case: incrementDate function allows you to include a date that is calculated based on an existing date field within Sora. It takes in three parameters: the date field, the increment quantity and the unit, as shown below:

<code>{{incrementDate startDateField 3 "day" "YYYY-MM-DD"}}<code>

Acceptable units:

  • "days"
  • "weeks"
  • "months"
  • "quarters"
  • "years"
  • negative numbers (i.e. -3 "days")

Other things to note:

  • The <code>incrementDate<code> function accepts a format string as an optional fourth parameter.
  • Once again, the date argument should follow the same camel-casing format described in the note in the Conditional Content Blocks section.

Increment date by business days

<code>incrementDateByBusinessDays<code> allows you to add or subtract business days from a date field within Sora and print it in a desired format. It takes a mandatory date field and the number of business days to add or subtract and an optional third parameter for formatting the result.

Examples:

  • <code>{{incrementDateByBusinessDays startDateField 3}}<code>
  • <code>{{incrementDateByBusinessDays endDateField -5 "YYYY-MM-DD"}}<code>