Formatting Date/Time Fields in a CRM Mail Merge

When you execute a Mail Merge in Microsoft CRM and include Date/Fields in the merge, that field exports the data in the following format:  "04/29/2009 12:30 PM".  The time is always exported as part of the merge even if the attribute in CRM is configured to display the Date only.  Well what if you wanted to change the formatting of a date field in your merge?  In CRM there are Merge Codes that you can use to format the output of data when performing a mail merge.

Here are a few samples of how you can use Merge Codes to format Date Fields:

Formatting a Date Field to Only Display the Date:

  1. In the Microsoft Word document generated for your mail merge, add the Date Field to the document (for example Created_On date for a record in CRM)
  2. Right-Click the merge field and Click Toggle Field Codes
  3. The display of the field will have changed from  <<CREATED_ON>>  to {MERGEFIELD CREATED_ON}
  4. Before the },  add the following:  \@ "mm/dd/yyyy",  now your field should look like this  {MERGEFIELD CREATED_ON \@ "mm/dd/yyyy"}
  5. Now when you go to the next step of your Merge and preview the document you will see that the time is no longer displayed.

Other Field Codes for Formatting Dates in a CRM Mail Merge:
- \@ "MMMM DD, YYYY"   - Formats the Date as:   April 29, 2009

CheatSheet for Date Formatting Codes:

  • dd - day as two numbers e.g. 01
  • d - single figures drop the zero e.g. 1.
  • dddd - day of the week e.g. Tuesday
  • ddd - day of the week in three letters e.g. Tue
  • MM - month as two figures e.g. 04
  • M - single figures drop the zero e.g. 4
  • MMMM - month in words e.g. April
  • MMM - month as three letters e.g. Apr
  • yy - year in two figures e.g. 05
  • yyyy - year in four figures e.g. 2005

There are Merge Codes available to format data of all types, Numbers, Money fields etc.

Jeremy





Published 04-29-2009 11:31 AM by Jeremy Winchell

Comments

# re: Formatting Date/Time Fields in a CRM Mail Merge

Tuesday, March 16, 2010 4:59 PM by Laurence Rose

Great tip!  

I don't suppose you know of any way this kind of formatting can be applied to date fields in an email template?

# re: Formatting Date/Time Fields in a CRM Mail Merge

Sunday, March 21, 2010 1:00 PM by Jeremy Winchell

Laurence,

If you're using the CRM E-Mail template functionality, not the Mail Merge via e-mail there are are a few things you can do in CRM.

1. Add a custom field that stores a text version of the data.  That way you can strip out the time that is usually included in the e-mail template.

2.  Utilize plug-ins or workflows for entities to again store dates as a string for use inside the e-mail template.

It would be nice if e-mail templates used the form logic as to whether or not to include the time in a date field, it's just not there yet.  Thankfully with the extensibility of Dynamics CRM there are other solutions to solve this problem.

- Jeremy