How do you change a date format in an email? Like 2014-04-30 to April 30, 2014

Anonymous
Not applicable

How do you change a date format in an email? Like 2014-04-30 to April 30, 2014

The goal is to send out renewal communications that merge in a universally accepted date field. What someone is used to in the states is different than what someone is used to in Europe.

Is there a way to adjust the way the date field looks when it's merged into an email? Any other workarounds? 

Use Case:
Want to send emails that say "Your upgrade is scheduled for deployment on March 1, 2014." instead of "Your upgrade is scheduled for deployment on 2014-03-01."

Token Example

Hi {{lead.First Name:default=}},

This is the enablement date: {{company.Enablement Date:default=Date}}



Tags (1)
14 REPLIES 14
Josh_Perry1
Level 7

Re: How do you change a date format in an email? Like 2014-04-30 to April 30, 2014

Hi Jeff,

I do not believe there is a way to do this yet.  I believe there is an idea on this found here: https://community.marketo.com/MarketoIdeaDetail?id=08750000000I4yfAAC.  I know it is not exactly the same, but it is similar.  I would add to the idea and like the idea. 
Anonymous
Not applicable

Re: How do you change a date format in an email? Like 2014-04-30 to April 30, 2014

Hi Jeff,

You can do this date conversion using an email script token.  The code to use in the script would be something like:

$date.format('MMM dd, yyyy', ${convert.parseDate($company.Enablement_Date__c, 'yyyy-MM-dd')})

You would want to use the drag-and-drop UI within the email script token editor to get the exact name of the field to reference (I just guessed at the format based on your post).

The one caveat is to make sure that the date field you're converting actually contains a value (if it's null, the script can fail silently on test messages and leave you no clue what's gone wrong).

The full script, including a test for a null value, would be:

#if ( $company.Enablement_Date__c )
  $date.format('MMM dd, yyyy', ${convert.parseDate($company.Enablement_Date__c, 'yyyy-MM-dd')})
#end

#* end your script with a comment so that it doesn't fail when returning no value *#

You could add more conditionals (if/then statements) to vary the format conversion by region if you wanted, as long as there's a field on the company or lead record that designates region.

If you try this, let me know whether it works.  I am using something just like it in several of our email messages and it works quite nicely.

-patrick
Josh_Perry1
Level 7

Re: How do you change a date format in an email? Like 2014-04-30 to April 30, 2014

Great post Patrick.  I am interested in testing this as well. 
Anonymous
Not applicable

Re: How do you change a date format in an email? Like 2014-04-30 to April 30, 2014

Thanks so much Patrick. This project is due this week so I'll be trying it out.  What's strange about the existing field is the standard date token as I showed above appears differently in an alert vs as email. Can't wait to try it out.


Anonymous
Not applicable

Re: How do you change a date format in an email? Like 2014-04-30 to April 30, 2014

Hi Jeff - 

I tried this out and it is working (so far) for me.  

Token name:
my.DemoTime

Code in the token: 
$date.format('MMM dd, yyyy hh:mm a', ${convert.parseDate(${lead.Demo_Appointment__c}, 'yyyy-MM-dd h:m')}

Code in the email:
We have you scheduled for {{my.DemoTime}} (Eastern Time)

How the line appears in the email:

We have you scheduled for Feb 18, 2014 03:00 PM (Eastern Time)

I had created a Salesforce custom lead field "Demo_Appointment__c" with datetime format.

Anonymous
Not applicable

Re: How do you change a date format in an email? Like 2014-04-30 to April 30, 2014

I'm having an issue with the date token as well. It is odd to assume that anyone would want a date to appear in an email as yyyy-mm-dd !

I tried the suggestions above and they work when I test my email, but not when the email is actually triggered to be sent by a smart campaign. Then the email just displays the token code.

Any suggestions??
Anonymous
Not applicable

Re: How do you change a date format in an email? Like 2014-04-30 to April 30, 2014

Hi Meirav -

The token code will get displayed as-is (without populating a date) if the field your referencing has a null value for a lead.  Have you checked to make sure all the leads flowing into your campaign have the date field populated? 

The other thing I do regularly is code email script tokens to "degrade gracefully".  That is, I code in a conditional statement or value so that if a field happens to be unexpectedly blank, the email that results still makes as much sense as possible.  I've found some wierd cases where Marketo occasionally has trouble accessing certain data in email token scripts (especially custom fields and custom objects) that are otherwise referenceable and accurate when you build your smart list.

Hope this helps!

-patrick
Anonymous
Not applicable

Re: How do you change a date format in an email? Like 2014-04-30 to April 30, 2014

The date field I'm referencing is definitely not blank. It gets populated through a required form field, so there's no way it would be blank. Yet, I'm still gettting the token code in the email field when the email is triggered from the smart campaign. But if I go in and send a test of the email it works. Very odd.
Anonymous
Not applicable

Re: How do you change a date format in an email? Like 2014-04-30 to April 30, 2014

Are you triggering an autoresponder from a form submission and trying to access field values that the lead just submitted?  If that's what you're doing, I would try waiting 10-15 minutes before triggerring the autoresponder to see whether that happens to let the form values populate on the lead record in Marketo in a way that makes them available in the email script token.  It's possible there's just enough lag that triggering the autoresponder immediately results in the script seeing a null value.

Or ... submit a support case.  🙂

-patrick