How to Change the Format of a Date in Custom Emails and Smart Documents

Learn how to customize the format for dates in emails and smart documents. The process depends on whether the data is a standard field or a custom field.

The code field of Custom Emails and Smart Documents is rendered into HTML (and then PDF) using the Velocity Templating Language, which gives you access to basic programming structures, such as variables, logic, and loops.

Using the power of the Velocity Templating Language, we can change how dates are formatted in these emails & documents.

By default, dates from Infoplus appear in custom email and smart documents like the following: 

  • 2020-10-20T00:00:00.00Z
    Changing the format of the date is dependent on if the date is a standard date field from Infoplus or a custom date field. 

    Formatting a Standard Date Field

    The value passed in by a standard date field is a date object, so we have access to methods like getMonth() and getYear().  An example of a standard date field is orderDate from the Order table.  The following example changes the format of the date to MM/DD/YYYY using these methods:

    This code set a variable called $orderDate.  To display this formatted date in the document, just add it somewhere in the HTML of the document.  For example:

    Formatting a Custom Date Field

    The value passed in by a date custom field is a string object, rather than a date object, so the getMonth() and getYear() methods used in the previous example will not work.  


    In this example, we have a custom field called expectedReceiptDate.  To change the format of the date to MM/DD/YYYY, we can use substring to pull out the information needed from the string.  The following velocity code will make this happen:

    This code set a variable called $shortDate.  To display this formatted date in the document, just add it somewhere in the HTML of the document.  For example:

    <span style="color: #000000;">$!shortDate</span>