Change Date Format Using Velocity Script and Tokens
I'm stumped. Been through many articles, even tried ChatGPT to find Velocity Script that changes the date format on a token in an email. I do have an Account field that pulls in the date successfully: {{Company.Renewal Date}}, but in the Mkto standard yyyy-MM-dd, or 2023-12-22. I want it to be MMMM dd, yyyy or December 22, 2023. Velocity script doesn't seem to support Account fields so I had my Sales Ops create a Contact field, {{lead.Account Renewal Date}} to pull in from the Account field. I CAN see this field in the VS objects list. My referring "my.token" in this case is {{my.RenewalDate}} and it "tries" to use the following VS to no avail.
Appreciate any feedback for fix suggestions.
#set( $dateOptions = {
"formats" : {
"userin" : "yyyy-MM-dd HH:mm:ss",
"userout" : "MMMM d, yyyy 'at' HH:mm:ss z"
},
"timezones" : {
"userin" : "America/New_York",
"userout" : "America/New_York"
},
"locale" : $date.getLocale()
})
#set( $renewalDatelike = $lead.account_renewal_date__c )
#set( $renewalDate = $convert.parseDate(
$renewalDatelike,
$dateOptions.formats.userin,
$dateOptions.locale,
$date.getTimeZone().getTimeZone($dateOptions.timezones.userin)
) )
#set( $renewalDate_formatted = $date.format(
$dateOptions.formats.userout,
$renewalDate,
$dateOptions.locale,
$date.getTimeZone().getTimeZone($dateOptions.timezones.userout)
) )
$renewalDate_formatted