Velocity script to return the last two characters in a string | Community
Skip to main content
Katja_Keesom
Community Manager
Nov 6, 2020 12:57 PM UTC
Solved

Velocity script to return the last two characters in a string

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.
SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
Nov 6, 2020 3:55 PM UTC
#set( $dateObj = $convert.parseDate( $lead.yourField, "yyyy-MM" ) ) ${date.format("MMMM", $dateObj, $convert.toLocale("nl_NL"))}

3 replies

Katja_Keesom
Community Manager
Nov 6, 2020 2:03 PM UTC

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".

Translate
SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
Nov 6, 2020 3:55 PM UTC
#set( $dateObj = $convert.parseDate( $lead.yourField, "yyyy-MM" ) ) ${date.format("MMMM", $dateObj, $convert.toLocale("nl_NL"))}
Translate
Katja_Keesom
Community Manager
Nov 9, 2020 6:35 AM UTC

Wow, I was overcomplicating again. Clean and effective.

Thank you!

Translate