Date Formats in Viewer
Date formats play a crucial role in your templates, In Viewer, one popular method for working with dates is through the use of the moment function.
{{moment Account.CreatedDate 'YY, MM DD'}}
{{moment Lead.CreatedDate format='DD/MM/YYYY'}}
{{moment Account.CreatedDate format='LL'}}
Here is an example for how to
Add 30 days to Opportunity Close date with some format
{{moment Opportunity.CloseDate add='days' amount='30'}}
Add 3 hours to Case Closed Date with format (Remember: Salesforce save the ClosedDate in UTC in the data base)
{{moment Case.ClosedDate format=' HH:mm DD/MM/YYYY ' add="3" addparam="h"}}
Use Today Date
{{moment (today) format='LT'}} 4:56 PM
{{moment (today) format='LTS'}} 4:56:03 PM
{{moment (today) format='L'}} 02/04/2024
{{moment (today) format='l'}} 2/4/2024
{{moment (today) format='LL'}} February 4, 2024
{{moment (today) format='ll'}} Feb 4, 2024
{{moment (today) format='LLL'}} February 4, 2024 4:56 PM
{{moment (today) format='lll'}} Feb 4, 2024 4:56 PM
{{moment (today) format='LLLL'}} Sunday, February 4, 2024 4:56 PM
{{moment (today) format='llll'}} Sun, Feb 4, 2024 4:56 PM
{{moment (today) add='days' amount='7'}}
{{moment (today) subtract='days' amount='7'}}
Manipulating Dates in Viewer
Viewer's moment function not only allows you to convert date formats but also enables you to manipulate dates easily. Let's say you have a date set with a "start_date" column, and you want to add 7 days to each date. With Moment, you can achieve this effortlessly.
Important note :Viewer Time Zone is UTC
Here's an example:
{{moment (today) add='days' amount='7'}}
{{moment d subtract='days' amount='7'}}
{{moment Case.ClosedDate format=' HH:mm DD/MM/YYYY ' add="7" addparam="h"}}
Timezone Handling for Salesforce Datetime Fields
Salesforce stores all datetime fields in UTC (Coordinated Universal Time) in the database. This universal time standard ensures consistency across global organizations but can lead to discrepancies when displaying these dates in different time zones. In Viewer, you can easily manipulate these datetime values to display them in your local timezone.
To adjust a datetime field from Salesforce's UTC to your local timezone, you can use the add
or subtract
parameters with the moment
function:
{{moment Case.ClosedDate format=' HH:mm DD/MM/YYYY ' add="7" addparam="h"}}
#Adjusts time for India Standard Time (UTC+5:30)
{{moment Opportunity.CloseDate format='HH:mm DD/MM/YYYY' add="5.5" addparam="h"}}
#Adjusts time for Pacific Standard Time (UTC-8)
{{moment Account.LastModifiedDate format='HH:mm DD/MM/YYYY' subtract="8" addparam="h"}}
Displaying Both UTC and Local Time
UTC: {{moment Case.ClosedDate format='HH:mm DD/MM/YYYY'}}
Local: {{moment Case.ClosedDate format='HH:mm DD/MM/YYYY' add="4" addparam="h"}}
Change date format dynamically
To change the date format based on Salesforce data, you can create either a text field or a text formula, and then pass the desired format to the template. Remember to query the newly created field and ensure that users are granted the necessary permissions.
see the next example:
{{moment Opportunity.CloseDate format=Opportunity.myformat__c}}
Time Format Function
The timeFormat function allows you to extract and format specific components from Salesforce time fields. This is particularly useful when working with time data that comes in the format HH:mm:ss.SSSZ
(e.g., 00:15:00.000Z
).
syntax
{{timeFormat timeValue format='HH:mm'}}
Supported Format Strings
Supported Format Strings
Format | Description | Example Output |
HH | Hour in 24-hour format | 00 , 15 , 23 |
mm | Minutes | 00 , 15 , 45 |
ss | Seconds | 00 , 30 , 59 |
SSS | Milliseconds | 000 , 123 , 999 |
HH:mm | Hour and minutes | 00:15 , 15:30 |
mm:ss | Minutes and seconds | 15:00 , 30:45 |
HH:mm:ss | Hour, minutes, and seconds | 00:15:00 , 15:30:45 |
Examples
Input time: 00:15:00.000Z
<!-- Extract hour -->
{{timeFormat Meeting_Start_Time__c format="HH"}}
<!-- Output: 00 -->
<!-- Extract minutes -->
{{timeFormat Meeting_Start_Time__c format="mm"}}
<!-- Output: 15 -->
<!-- Display hour and minutes -->
{{timeFormat Meeting_Start_Time__c format="HH:mm"}}
<!-- Output: 00:15 -->
<!-- Full time display -->
{{timeFormat Meeting_Start_Time__c format="HH:mm:ss"}}
<!-- Output: 00:15:00 -->
Meeting starts at {{timeFormat Start_Time__c format="HH:mm"}}
and ends at {{timeFormat End_Time__c format="HH:mm"}}
<!-- Output: Meeting starts at 09:30 and ends at 10:30 -->
{{#if Start_Time__c}}
Start: {{timeFormat Start_Time__c format="HH:mm"}}
{{else}}
No start time specified
{{/if}}
Use Hebrew Date
{{heDate (today)}}
{{heDate Opportunity.CloseDate }}
Use Date units
{{moment d 'millisecond'}}
{{moment d 'second'}}
{{moment d 'minute'}}
{{moment d 'hour'}}
{{moment d 'date'}}
{{moment d 'day'}}
{{moment d 'weekday'}}
{{moment d 'weekday' type='s'}}
{{moment d 'weekday' type='xs'}}
{{moment d 'weekday' type='number'}}
{{moment d 'isoweekday'}}
{{moment d 'dayofyear'}}
{{moment d 'week'}}
{{moment d 'isoweek'}}
{{moment d 'month'}}
{{moment d 'year'}}
{{moment d 'weekyear'}}
{{moment d 'isoweekyear'}}