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.
momentβ Format or transform a datedurationβ 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"}}
04/02/2024Add Days to a Dateβ
{{moment Opportunity.CloseDate add="days" amount="7" format="YYYY-MM-DD"}}
2024-02-11Subtract Days from a Dateβ
{{moment Opportunity.CloseDate subtract="days" amount="3" format="YYYY-MM-DD"}}
2024-02-01Friendly Relative Dateβ
{{moment Opportunity.CreatedDate "fromNow"}}
2 days agoCalendar Style Dateβ
{{moment Opportunity.CloseDate "calendar"}}
Tomorrow at 3:00 PMCommon 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 Code | Description | Example Output |
|---|---|---|
LT | Time | 4:56 PM |
LTS | Time with seconds | 4:56:03 PM |
L | Date (numeric) | 02/04/2024 |
l | Date (numeric, short) | 2/4/2024 |
LL | Date (long) | February 4, 2024 |
ll | Date (abbreviated) | Feb 4, 2024 |
LLL | Date + Time (long) | February 4, 2024 4:56 PM |
lll | Date + Time (abbreviated) | Feb 4, 2024 4:56 PM |
LLLL | Day, Date + Time (long) | Sunday, February 4, 2024 4:56 PM |
llll | Day, Date + Time (short) | Sun, Feb 4, 2024 4:56 PM |
Native Output Formatsβ
These native modes return specific date values without a format parameter:
| Mode | Description | Example Output |
|---|---|---|
fromNow | Relative time from now | 2 days ago |
from | Relative time from a point | in 5 days |
calendar | Calendar-friendly format | Tomorrow at 3:00 PM |
str | Date string | Sun Feb 04 2024 16:56:03 |
val | Milliseconds since epoch | 1707077763000 |
unix | Seconds since epoch | 1707077763 |
daysinmonth | Number of days in month | 29 |
todate | Full date string | Sun Feb 04 2024 16:56:03 GMT+0000 |
array | Date as array | [2024, 1, 4, 16, 56, 3, 0] |
isostring | ISO 8601 format | 2024-02-04T16:56:03.000Z |
Usage Examplesβ
{{moment Opportunity.CloseDate "unix"}}
{{moment Opportunity.CloseDate "isostring"}}
{{moment Opportunity.CloseDate "daysinmonth"}}
unixβ1707077763isostringβ2024-02-04T16:56:03.000Zdaysinmonthβ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 Code | Language | Example Output (LL format) |
|---|---|---|
en | English | February 4, 2024 |
fr | French | 4 fΓ©vrier 2024 |
de | German | 4. Februar 2024 |
he | Hebrew | 4 ΧΧ€ΧΧ¨ΧΧΧ¨ 2024 |
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
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β
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"}}
2 hoursDuration as Specific Unitβ
{{duration Case.SLA_Duration__c as="hours"}}
2Real-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"}}
Created: 15 Jan 2024 Close: 04 Feb 2024
Best Practicesβ
- Always specify
formatfor 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: