Formatting Dates

If you want to create a dated letter with the text “September 1, 2020” rather than the Salesforce formatted date-time, you can do so using S-Docs formatting syntax or using a Salesforce formula field. We recommend the first option where possible because it doesn’t require any Salesforce configuration changes.

Formatting Dates With S-Docs Syntax

Formatting dates with S-Docs syntax is easy; any Salesforce date and datetime field can be configured into any valid java pattern. Simply add a space in your date or datetime merge field, followed by the format you want:

{{!Quote.createdDate MM/dd/yyyy}}

You can also format time and timezone. For example:

{{!Quote.datetime__c MM/dd/yyyy hh:mm:ss TZ:America/New_York}}
Note: Make sure to use java time codes when using timezones.

If the date field is located in a related list column, use the following (you would need to edit the template source). Click the Source button and then locate the date column within your template.

<column format-date="MM/dd/yyyy">createddate</column>

The format-date syntax can accept a wide range of values. You can add minutes, timezones, etc. Pay attention to caps, as mm is minutes, whereas MM is month.

Use this reference to view all date formatting options:  https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

Formatting Dates With Salesforce Formula Fields

If S-Docs syntax options do not meet your requirements, you can format dates by leveraging Salesforce formula fields. By adding the following formula field to your object, you can leverage Salesforce functionality. You would need to substitute your field name. You do not need to add these fields to any page layout. If you are working with a Date Field (not a DateTime field), see the next example for slight modifications needed.

CASE( MONTH( DATEVALUE(LastModifiedDate) ), 1, "January", 2, "February", 3, "March", 4, "April", 5, "May", 6, "June", 7, "July", 8,
"August", 9, "September", 10, "October", 11, "November", 12, "December", "-" )
+ ' ' + TEXT(DAY( DATEVALUE(LastModifiedDate))) + ', ' + TEXT(YEAR( DATEVALUE(LastModifiedDate)))

Tags: ,

Was this helpful?