Velocity script to return the last two characters in a string | Community
Skip to main content
Katja_Keesom
Community Manager
November 6, 2020
Solved

Velocity script to return the last two characters in a string

  • November 6, 2020
  • 1 reply
  • 2220 views

I have an existing lead field that contains the value for a specific month, presented as YYYY-MM.

From this, I want to set up a script token that only returns the value for the month, irrespective of which year is indicated. I have the section of script to translate the MM value into "January", but I am struggling to strip the year indicator from the original value.

I looked into substring and truncate options, but have not found a working solution.

 

Does anyone have a suggestion?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman
#set( $dateObj = $convert.parseDate( $lead.yourField, "yyyy-MM" ) ) ${date.format("MMMM", $dateObj, $convert.toLocale("nl_NL"))}

1 reply

Katja_Keesom
Community Manager
November 6, 2020

I just knew there had to be a @sanfordwhiteman post out there somewhere that would help, and indeed!

Got there most of the way with the solution in this post: https://nation.marketo.com/t5/Product-Discussions/How-do-I-modify-the-date-format-for-a-token-using-Velocity/td-p/100308

Now just looking for a way to represent the MMMM in nl_NL locale so it shows the Dutch version of "January".

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
November 6, 2020
#set( $dateObj = $convert.parseDate( $lead.yourField, "yyyy-MM" ) ) ${date.format("MMMM", $dateObj, $convert.toLocale("nl_NL"))}
Katja_Keesom
Community Manager
November 9, 2020

Wow, I was overcomplicating again. Clean and effective.

Thank you!