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

Anonymous
Not applicable
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
Anonymous
Not applicable
I'm surprised every person trying to set up a renewal notification isn't requesting this feature. I'll add my vote to the request for a more user-friendly method to specify how to display dates.
Anonymous
Not applicable
Thanks Patrick.

I checked my script and everything looks fine. It's the same as the one you provided except i have changed the field value. I still can't figure out where the extra space is coming from. I appreciate the feedback though.
Anonymous
Not applicable
I wanted to circle back. We were never able to get the code from above working. However, we didn't try too long as we stumbled across a very weird workaround. The workaround makes no sense but I'd be curious if others experienced the same results.

We use the regular date token as shown below, not the email script token.

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

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

Here is where it gets weird......
 
When we drop the email into a Request Campaign campaign to send the email, the Enablement date merges in the way we want it (Mar 20, 2014).  However, if the same email is sent via a batch campaign, the email merges in that field in the 2014-20-03 format. 

So instead of sending the email via a a batch, we set up another campaign to grab the members. We then request a second campaign that contains Send Email in the flow.

The only reason why we stumbled on this is we were originally using the advanced wait token as part of a Request Campaign campaign.
Anonymous
Not applicable
@Brenton, check for any extra and unnecessary spaces in your script, especially at the end of the last line.  You're very likely to get extra spaces from your script in the plain text version of your message or if your message is text-only (no html formatting). 
Anonymous
Not applicable
The code is working fine on my side; however, after it changes the value, there is a blank space after the date. So for example:

Feb 20 2014 . 

There is a tiny space after the 2014. I couldn't figure out why, any thoughts?
Anonymous
Not applicable
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
Anonymous
Not applicable
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
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
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
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
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.


Josh_Perry1
Level 7
Great post Patrick.  I am interested in testing this as well. 
Anonymous
Not applicable
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
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.