Data Formats and Date Manipulation Techniques in Viewer
Data Formats in Viewer
Data 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'}}
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 dataset 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 GMT
Here's an example:
{{moment (today) add='days' amount='7'}}{{moment d subtract='days' amount='7'}}
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}}
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'}}