Date Token Appearance

Anonymous
Not applicable

Date Token Appearance

Can you alter the way a Date Token appears? It is displaying on the Date Token itself as Jun 5, 2014 but when the token is inserted into an email, it's previewing as 2014-05-05. I want the final appearance to be Month, Day, Year. Is this possible? 
Tags (1)
9 REPLIES 9
Anonymous
Not applicable

Re: Date Token Appearance

It's a bit of extra work but if you use My.Token in a program you can use the email scripting option to transform the date as you wish. 

program -> My tokens -> Email Script 
Name token 
Then copy and paste the code below into the editor, replacing "your_field" with the name of your date field

$date.format("MM/dd/yyyy", $convert.parseDate(${lead.your_field}, "yyyy-MM-dd"))
Anonymous
Not applicable

Re: Date Token Appearance

I used your code to create My Token in the Program:

$date.format("MM/dd/yyyy", $convert.parseDate(${lead.WarrantyExpirationDate}, "yyyy-MM-dd"))

I applied this in the html body:

{{my.WarrantyExpirationDateFormatted}}

The email displayed the code literally.

What's missing?

SanfordWhiteman
Level 10 - Community Moderator

Re: Date Token Appearance

  1. Ensure you have checked off the lead.WarrantyExpirationDate field for inclusion in the Velocity script.
  2. You should always take timezones into account, even for strings that appear to be only dates.  Date objects always have timezones and this can cause unexpected (and not in a good way) results.
  3. See my responses tp Get time from timestamp andSet local timezone using Velocity scripts
Anonymous
Not applicable

Re: Date Token Appearance

I did the above setps. Named the Email script token Date_Converter. I leave the Webcast_Date token there, yes? And replaced the "your_field" in the code with "Webcast_Date". It's not changing anything in the email asset when previewed. Date still reads "yyyy-MM-dd" and not how I'd like it to ready which is "MM/dd/yyyy". Do I need to insert the Email script token I just created "Date_Converter" into the email asset? I did try inserting it in the email asset and it didn't do anything. Does this email script run from the token campaign page without needing to insert it anywhere?
0EM50000000RqMK.jpg
Anonymous
Not applicable

Re: Date Token Appearance

I understand the script token needs to be inserted in lieu of the date token, but I'm getting an error using my date token in the code provided above:

I defined a date toke: {my.event date}
But $date.format("MM/dd/yyyy", $convert.parseDate(${my.event date}, "yyyy-MM-dd")) causes an error when sending the email.

Anonymous
Not applicable

Re: Date Token Appearance

Did you find an answer to using {my.event date}? We are also having a problem using the date token.

Anonymous
Not applicable

Re: Date Token Appearance

Really sorry I'm only seeing this comment now. I hope you since figured it out.

In your code you are placing the my token in,

$date.format("MM/dd/yyyy", $convert.parseDate(${my.event date}, "yyyy-MM-dd"))

you should be placing the name of your lead field in here not the name of the token.

Courtney O'Donnell​ It won't work with my/program token values only database field values.

I think an easier solution for you would be to use a text  program token instead of a date program token. That way you can write the format whatever way that you want.

Anonymous
Not applicable

Re: Date Token Appearance

I don't think you can nest operations like you're trying to do in the code snippet you provided. I was able to accomplish this by setting a variable and using it as an input to the outer operation:

#set($str = $convert.parseDate(${lead.HEye_Trigger_Expire__c}, "yyyy-MM-dd"))
$date.format("MM/dd/yyyy",$str)


Here's where I got the idea:
http://stackoverflow.com/questions/22150952/string-to-date-with-convert

Anonymous
Not applicable

Re: Date Token Appearance

This worked perfectly for me. Thanks!