When I insert a token date field into an HTML email, the default format is yyyy-mm-dd.
Does anyone know how to reformat the date as a long date? Example: Sunday, October 19, 2003
I think I need to create a new Email Script Token in my Program, but I don't know how to write javascript.
Based on what I read here:
http://developers.marketo.com/documentation/velocity-script/script-examples/
I found some sample code (below).
I want to reformat this field: lead.WarrantyExpirationDate
Desired format (long date): Sunday, October 19, 2003
I think the long date field is: $date.full_date
I know that I need to navigate to: Marketo > My Program > My Tokens > New > Email Script
and create a script for My Token {{WarrantyExpirationDate2}}.
I found these examples:
Script Examples » Marketo Developers
##create a date and parse it with a format
##parseDate takes two args, a date string and the format
#set($myDate = $convert.parseDate("08-07-2015", "MM-dd-yyyy"))
##format the date
##format takes two args, the format and a date object
#set($formattedDate = $date.format("yyyy-MM-dd", $myDate))
${formattedDate}
I found another example here, but I don't know how to modify it for the long/full date format with my field names and I don't know which of these examples will work.
#set($myDate = $convert.parseDate(${lead.eventdate}, "dd-MM-yyyy"))
#set($formattedDate = $date.format("yyyy-MM-dd", $myDate))
${formattedDate}
Thanks in advance for your help!
Solved! Go to Solution.
I'm in Eastern time zone if that helps
Obviously it helps. I don't know why you can't see how critical that is. Every time you look at a clock you're using timezones. What you may not realize is that when you ask a computer, "Tell me the current day of the week," if you don't specifically say "Tell me the current day of the week in New York City" it may tell you the current day of the week in wherever it thinks it's physically located, or the current day of the week in Greenwich, England (source of UTC/GMT time). Plus, where the computer operates geographically (based on the audience it serves) might have nothing to do with where it is physically located, so even when you say "Tell me what time it is where you are" you can still get a totally wrong answer.
And even something as seemingly mind-numbingly simple and un-mess-uppable as "Tell me the year from the string '2016-09-30'" is not actually simple, since strings are not dates, and in order to convert them to dates in order to format them you need to... supply a time zone.
Anyway, assuming your input format is
yyyy-MM-dd (note capital MM, not lowercase, is the 2-digit month)
To output in your format, use the following Velocity script:
#set( $inTimeZone = $date.getTimeZone().getTimeZone('America/New_York') )
#set( $outTimeZone = $date.getTimeZone().getTimeZone('America/New_York') )
#set( $locale = $date.getLocale() )
#set( $myDate = $convert.parseDate($lead.WarrantyExpirationDate,'yyyy-MM-dd',$locale,$inTimeZone) )
${date.format('EEEE, MMMM dd, yyyy',$myDate,$locale,$outTimeZone)}