SOLVED

Re: Velocity Scripting to Format Date Token

Go to solution
Simone_Williams
Level 2

Velocity Scripting to Format Date Token

Hi All!

I have read through the community and haven't found a solution to my problem so I'm hoping someone can help.

 

I need to reformat a date token so it displays like this in the email: MM DD, YYYY

 

Here is the token: {{company.Expire Date (mkto)}}

 

I have tried a few solutions I found in the community but none of them displayed properly for me. I also am not seeing the field 'company.Expire Date (mkto)' pop up in the "tree" so I can't check it off/select it. 

 

I was wondering if I am having trouble because this is a SFDC custom field?

 

If anyone can help, please chime in. Also, if I need to provide any additional information, I'm happy to!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Simone_Williams
Level 2

Re: Velocity Scripting to Format Date Token

@Sahil_Kumar_Chh  messaged me privately and provided the solution. Shout out to him and everyone else who chimed in to help me! I appreciate it! I just replaced the field ${lead.DateofBirth} highlighted below to make it work for me. Thanks again all.

 

#set( $dateOptions = {
"formats" : {
"userin" : "yyyy-MM-dd",
"userout" : "MMM d, yyyy"
},
"timezones" : {
"userin" : "America/Los_Angeles",
"userout" : "America/Los_Angeles"
},
"locale" : $date.getLocale()
} )

#set( $myDatelike = ${lead.DateofBirth} )
#set( $myDate = $convert.parseDate(
$myDatelike,
$dateOptions.formats.userin,
$dateOptions.locale,
$date.getTimeZone().getTimeZone($dateOptions.timezones.userin)
) )

#set( $myDate_formatted = $date.format(
$dateOptions.formats.userout,
$myDate,
$dateOptions.locale,
$date.getTimeZone().getTimeZone($dateOptions.timezones.userout)
) )

${myDate_formatted}

 

View solution in original post

6 REPLIES 6
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Velocity Scripting to Format Date Token

I think we'd need to see the existing date format of the field. What do you see as output when you just display the unformatted value of that field in an email for a person with a non-empty value?

 

Additionally, Account (or Company) fields can be referenced in the email script token in the Person Object (as $lead.field_name), of course, given that they're visible and synced over to Marketo. Could you open up the Standard Objects >> Person in your email script token's tree on the right and verify whether you're able to see that field?

Simone_Williams
Level 2

Re: Velocity Scripting to Format Date Token

Thanks for your quick response. 

Presently, the date is displaying: YYYY-MM-DD

 

I do see it under Standard Objects. Thanks for that tip, I was looking in the wrong area.

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting to Format Date Token

Adapt the code from this thread. You should also read the seminal Velocity DateTime post.

Simone_Williams
Level 2

Re: Velocity Scripting to Format Date Token

@Sahil_Kumar_Chh  messaged me privately and provided the solution. Shout out to him and everyone else who chimed in to help me! I appreciate it! I just replaced the field ${lead.DateofBirth} highlighted below to make it work for me. Thanks again all.

 

#set( $dateOptions = {
"formats" : {
"userin" : "yyyy-MM-dd",
"userout" : "MMM d, yyyy"
},
"timezones" : {
"userin" : "America/Los_Angeles",
"userout" : "America/Los_Angeles"
},
"locale" : $date.getLocale()
} )

#set( $myDatelike = ${lead.DateofBirth} )
#set( $myDate = $convert.parseDate(
$myDatelike,
$dateOptions.formats.userin,
$dateOptions.locale,
$date.getTimeZone().getTimeZone($dateOptions.timezones.userin)
) )

#set( $myDate_formatted = $date.format(
$dateOptions.formats.userout,
$myDate,
$dateOptions.locale,
$date.getTimeZone().getTimeZone($dateOptions.timezones.userout)
) )

${myDate_formatted}

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting to Format Date Token

@Sahil_Kumar_Chh  messaged me privately and provided the solution.

Hmm, that’s unfortunate, as the Nation community is supposed to be for public discussion and public solutions.

 

In any case the code is taken from the post I linked to (it’s actually my code!).

 

But you shouldn’t be using the formal reference ${lead.DateofBirth} here. Use the simple reference style $lead.DateofBirth unless you’re outputting values.

Sahil_Kumar_Chh
Level 2

Re: Velocity Scripting to Format Date Token

@SanfordWhiteman Definitely. I privately messaged with some inquiries about the field and made some adjustments to the given post by removing the foreach loop.