Hi, I need to change the standard date format from: 2017-02-27 to 27 February 2017 for an email send to a list of leads with a specific date for each.
I'm using a token for a Contract Date field: {{lead.Contract Date}} which produces the standard format 2017-02-27
The date in the lead record for the Contact Date field begins like this: Feb 27, 2017
Reading throughout the community on how to fix this and it's not as clear as I'd like but nonetheless I'm reaching out to see if there's a clear-cut answer as to how to code the velocity script and step by step instructions so it works. I understand I can use a My.token at the program level and code it in velocity script, but from there I need more guidance. Thanks! -T
Solved! Go to Solution.
What time zone are those dates in (yes, this is an important detail when converting)?
Hi Trinity,
You will find a lot of useful info:
http://blog.teknkl.com/marketo-vtl-strings-all-the-way-down/
How to reformat date Token field as full date?
-Greg
Checking out these links, Yes the time zone is important as I'm reading what Sanford said and going to attempt to fix this myself based off the similar conversation another lady had, but my client is asking that I spell out the month...that seems a bit more involved, is there additional code to render each unique month into it's corresponding word? Many Thanks!!!
Date format macro for the full month is MMMM. Thus when outputting the date/calendar object $contractDate:
${date.format("d MMMM yyyy",$contractDate)}
Sanford Whiteman I tried replacing the last line of code with this:
${date.format("d MMMM yyyy",$contractDate)}
But it rendered incorrect: ${date.format("d MMMM yyyy",$contractDate)} , and I'm too curious not to understand my mistake, what did I do wrong?
Probably because you aren't using the variable name $contractDate. You'd replace that with the actual variable name declared earlier in your code.
Hmm sorry Sanford not sure about that, I'm still learning and I tried something and it didn't work, thus I keep trying
Works great for this format: Monday, February 27, 2017
#set( $inTimeZone = $date.getTimeZone().getTimeZone('America/Chicago') )
#set( $outTimeZone = $date.getTimeZone().getTimeZone('America/Chicago') )
#set( $locale = $date.getLocale() )
#set( $myDate = $convert.parseDate($lead.contractDate,'yyyy-MM-dd',$locale,$inTimeZone) )
${date.format('EEEE, MMMM dd, yyyy',$myDate,$locale,$outTimeZone)}
Sure, that looks like my go-to code there.
The line that begins
${date.format(...
uses variables declared earlier ($myDate, $locale, etc.).
Sanford Whiteman I'm getting a nasty error when I use this:
Why can't I be as smart as you?!?! I just want to know the answer!!
#set( $inTimeZone = $date.getTimeZone().getTimeZone('America/Chicago') )
#set( $outTimeZone = $date.getTimeZone().getTimeZone('America/Chicago') )
#set( $locale = $date.getLocale() )
#set( $myDate = $convert.parseDate($lead.contractDate,'yyyy-MM-dd',$locale,$inTimeZone)
${date.format('d MMMM yyyy',$myDate,$locale,$outTimeZone)}
You put the code in an Email Script (Velocity) token, right?
Hi Sanford, Yes the velocity email script token was used, just replaced the code.
Can you show me a screenshot of the Email Script Editor with your code in it?
And you're sure (a) you have Contract Date selected in the right-hand tree and (b) that its VTL variable name is $lead.contractName? I would expect it to be $lead.Contract_Name given Velocity naming conventions.
the Contract Date field value is: ${lead.contractDate}
this is the current script for this format: Monday, February 27, 2017 I replaced the error script so that I can get this email out as it's a rush for today
Ok thank you I just tried the other way from the third link that Greg provided and it worked!!
Monday, February 27, 2017
I'm going to try this new code you just provided but I think my internal client will accept either option, thanks to you both, always appreciated how helpful and quick you are!!!
What time zone are those dates in (yes, this is an important detail when converting)?
Central Standard Time