Re: Velocity Script to Localize PMCF Event Date Tokens + the ability to hide if PMCF is empty

Diana-Gilman
Level 1
I am trying to use Velocity to output a PMCF date/time field/token for my Event email templates to display the date format in the specified language (also a PMCF field as this not only unique per user, it would be unique per user plus Event Program). 
 
Date Format: MMMM dd, yyyy hh:mm
Output: 2025-12-12 13:00:00
 
I found the following post on Marketo Nation, and it works great! https://nation.marketo.com/t5/product-discussions/set-local-timezone-using-velocity-scripts/td-p/196.... But I would also like to format these fields in various language date formats (fr_FR, de_DE, es_ES, etc.) 
 
Examples:
German: 12. Dezember 2025
French: 12 décembre 2025
Spanish: 12 de diciembre de 2025
 
I'm looking to set up two PMCF date/time fields: one for the Event Start Date+Time ({{member_EventStartDateTime}}) and another for the Event End Date+Time ({{member_EventEndDateTime}}). Additionally, if the Event is only a single day event, I'd like to be able to hide the {{member_EventEndDateTime}} if the value is empty. Otherwise, I get an output that looks like this "December 9th, 2025 - December 9th, 2025" which is not ideal. 
 
Please note that these PMCFs will be populated via API. Any recommendations on how I might be able to accomplish this? 
1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator
#set( $locale = $convert.toLocale("fr_FR") )
#set( $formatString = "dd MMMM yyyy" )
#set( $formattedStartDate = $date.format($formatString, $startDate, $locale) )
#set( $formattedEndDate = $date.format($formatString, $endDate, $locale) )
${formattedStartDate}#if( !$formattedStartDate.equals($formattedEndDate) ) - ${formattedEndDate}#end