Skip to main content

Data Formats and Date Manipulation

Use Viewer date helpers to display dates in the format your document needs. Format dates, add or subtract time periods, and display durations with the moment and duration helpers.

Quick Reference
  • moment – Format or transform a date
  • duration – Format a duration (time length)
  • heDate – Convert a date to a Hebrew/Jewish date string

Overview​

The Viewer template engine provides powerful date helpers to format Salesforce date fields in your documents. You can:

  • Format dates in any pattern (DD/MM/YYYY, localized formats, etc.)
  • Add or subtract time periods (days, months, years)
  • Display relative dates like "2 days ago" or "Tomorrow at 3:00 PM"
  • Support multiple locales for international document templates
  • Format durations for time tracking and SLA fields

Most Common Examples​

Format a Date​

{{moment Opportunity.CloseDate format="DD/MM/YYYY"}}
Output:04/02/2024

Add Days to a Date​

{{moment Opportunity.CloseDate add="days" amount="7" format="YYYY-MM-DD"}}
Output:2024-02-11

Subtract Days from a Date​

{{moment Opportunity.CloseDate subtract="days" amount="3" format="YYYY-MM-DD"}}
Output:2024-02-01

Friendly Relative Date​

{{moment Opportunity.CreatedDate "fromNow"}}
Output:2 days ago

Calendar Style Date​

{{moment Opportunity.CloseDate "calendar"}}
Output:Tomorrow at 3:00 PM

Common Format Patterns​

These are localized format codes that adapt to your locale settings:

{{moment (today) format='LT'}}
{{moment (today) format='LTS'}}
{{moment (today) format='L'}}
{{moment (today) format='l'}}
{{moment (today) format='LL'}}
{{moment (today) format='ll'}}
{{moment (today) format='LLL'}}
{{moment (today) format='lll'}}
{{moment (today) format='LLLL'}}
{{moment (today) format='llll'}}
Format CodeDescriptionExample Output
LTTime4:56 PM
LTSTime with seconds4:56:03 PM
LDate (numeric)02/04/2024
lDate (numeric, short)2/4/2024
LLDate (long)February 4, 2024
llDate (abbreviated)Feb 4, 2024
LLLDate + Time (long)February 4, 2024 4:56 PM
lllDate + Time (abbreviated)Feb 4, 2024 4:56 PM
LLLLDay, Date + Time (long)Sunday, February 4, 2024 4:56 PM
llllDay, Date + Time (short)Sun, Feb 4, 2024 4:56 PM

Native Output Formats​

These native modes return specific date values without a format parameter:

ModeDescriptionExample Output
fromNowRelative time from now2 days ago
fromRelative time from a pointin 5 days
calendarCalendar-friendly formatTomorrow at 3:00 PM
strDate stringSun Feb 04 2024 16:56:03
valMilliseconds since epoch1707077763000
unixSeconds since epoch1707077763
daysinmonthNumber of days in month29
todateFull date stringSun Feb 04 2024 16:56:03 GMT+0000
arrayDate as array[2024, 1, 4, 16, 56, 3, 0]
isostringISO 8601 format2024-02-04T16:56:03.000Z

Usage Examples​

{{moment Opportunity.CloseDate "unix"}}
{{moment Opportunity.CloseDate "isostring"}}
{{moment Opportunity.CloseDate "daysinmonth"}}
Outputs:
  • unix β†’ 1707077763
  • isostring β†’ 2024-02-04T16:56:03.000Z
  • daysinmonth β†’ 29

Multiple Locale Support​

Format dates in different languages using the lang parameter:

{{moment Opportunity.CloseDate lang="en" format="LL"}}
{{moment Opportunity.CloseDate lang="fr" format="LL"}}
{{moment Opportunity.CloseDate lang="de" format="LL"}}
{{moment Opportunity.CloseDate lang="he" format="LL"}}
Locale CodeLanguageExample Output (LL format)
enEnglishFebruary 4, 2024
frFrench4 fΓ©vrier 2024
deGerman4. Februar 2024
heHebrew4 ב׀ברואר 2024
Best Practice

If your org uses one default locale, keep it consistent across all templates for a uniform user experience.

Hebrew Date Helper (heDate)​

Use heDate when you need a Hebrew/Jewish date string output.

What heDate does​

  • Accepts a date value and converts it to Hebrew/Jewish date format
  • Returns an empty string for undefined/null/object inputs
Input type note

heDate expects a date value (for example, a date string/field value). If you pass an object value, the helper returns an empty string.

Usage Examples​

heDate with Salesforce field
{{heDate Opportunity.CloseDate}}
heDate with literal date
{{heDate "2024-02-04"}}

Output: Hebrew/Jewish date text (formatted in Hebrew)

Duration Examples​

Use the duration helper to format time lengths:

Human-Readable Duration​

{{duration Case.SLA_Duration__c "humanize"}}
Output:2 hours

Duration as Specific Unit​

{{duration Case.SLA_Duration__c as="hours"}}
Output:2

Real-World Example​

Here's how to display multiple dates in a document section:

Created: {{moment Opportunity.CreatedDate format="DD MMM YYYY"}}
Close: {{moment Opportunity.CloseDate format="DD MMM YYYY"}}
Output:
Created: 15 Jan 2024
Close: 04 Feb 2024

Best Practices​

Key Tips
  • Always specify format for predictable output across different orgs
  • One helper per line keeps templates readable and maintainable
  • Test timezone/locale behavior in your org before publishing templates

Common Use Cases​

How do I format a Salesforce date field?​

Use the moment helper with a format parameter:

{{moment Account.CreatedDate format="MM/DD/YYYY"}}

How do I add 30 days to a date?​

Use the add parameter with amount:

{{moment Opportunity.CloseDate add="days" amount="30" format="YYYY-MM-DD"}}

How do I show "X days ago" format?​

Use the fromNow native mode:

{{moment Case.CreatedDate "fromNow"}}

How do I format dates for different countries?​

Use the lang parameter with appropriate locale code:

{{moment Invoice.Date lang="fr" format="LL"}}

How do I display time duration in hours or minutes?​

Use the duration helper:

{{duration Task.Duration__c as="hours"}}

How do I display a date in Hebrew/Jewish format?​

Use the heDate helper:

{{heDate Opportunity.CloseDate}}

More resources​