SOLVED

How do I modify the date format for a token using Velocity Script?

Go to solution
Highlighted
Anonymous
Not applicable

Re: How do I modify the date format for a token using Velocity Script?

Hi Phillip,

I don't see a way to PM you through Marketo...Is there something you see that I don't?

Thank you,

Laura

Highlighted
Level 10 - Community Moderator

Re: How do I modify the date format for a token using Velocity Script?

Can you please explain what you mean by "creating Date objects from strings"? What are the strings that comprise the Expiration Date token and what are the date objects they become?

Your Expiration Date field may be set up as a Date type in Marketo, but when it's made visible in Velocity (as $lead.ExpirationDate or $lead.expirationDate or whatever you see when you choose it from the tree) it's merely a "date-like string" (that's a why I use $expirationDatelike as the variable name).

Essentially, you get the display version of what may or may not originally have been a Date variable (it could've been a custom String field in Marketo and it would look the same in Velocity).

The string value "2017-07-01" has no built-in date-like qualities: you can't reformat it as 'MMMM dd, yyyy', you can't add or subtract days from it, you can't set its timezone, etc. So it's not actually "a date" from a computer's standpoint, it only looks kind of like one to us humans.

But you can parse it into an intelligent Date object, since it follows one of well-known formats ('yyyy-MM-dd'). Once it's a real date ($expirationDate) you get the special date methods for reformatting, time calculation, etc.

Date fields being presented in Marketo's Velocity implementation as strings is a Marketo thing, not a Velocity thing.  Velocity as a language was developed far outside of Marketo, and it does support Date fields directly. So $lead.expirationDate could've already been a Date, technically speaking, but Marketo chose not to do it that way. Important to note the distinction, since when you're learning Velocity almost 100% of the examples on the net are not Marketo-specific. (My blog is a notable exception : http://blog.teknkl.com/tag/velocity.)

Is the variable my $dateOptions an "arbitrary" variable or is it one that is used often in velocity scripting? That is, is it a "standard" variable (for lack of a better term) or was it created for a specific purpose? If standard, are there other standard variables?

Completely custom variable. Any $var that gets #set in a script token is not built-in or standard.

There are several standard objects ("tools") with a range of built-in methods: Apache Velocity Tools - Generic Tools

But you also get access to a far wider, almost mind-blowing range of Java methods, depending on what kind of data you're dealing with. Velocity overlaps with Java -- it's neither a superset nor merely a subset of Java -- but can dip into some hugely powerful parts of the Java language as well as its own Velo-only functionality.

Where would be a good place to start to get a better grasp of programming in general and how Velocity functions as a programming language?

I love/hate these questions!

I'd def'ly point you to my blog, where my Velocity posts and stuff like the Code Anatomy series (http://blog.teknkl.com/tag/code-anatomy) try to take a bottom-up approach to how to build functions for some common needs. Since I work mostly in martech and its environs, the cases are likely to be more familiar than on a general programming blog. (I have a few Code Anatomy posts in Drafts that I really need to get out.)

I'm also really happy to chat for a bit about going in a mar-technical direction. Just follow me here and then we can DM each other and set it up. I have periodic apprentice-type sessions with a few people on the Community and am happy to take on another.

Highlighted
Anonymous
Not applicable

Re: How do I modify the date format for a token using Velocity Script?

Hi Sanford!

Thanks so much...Great information! I have another question (custom-object-field related) that I'm going to post right now.

I would definitely like to be added to your apprenticeship group. I'll follow you in a sec.

Thanks again!

Laura

Highlighted

Re: How do I modify the date format for a token using Velocity Script?

Hi Sanford,

I would also be interested on those apprenticeship sessions.

What would be the best way to discuss about that?

Thanks

Anne-Sophie

Highlighted
Level 10 - Community Moderator

Re: How do I modify the date format for a token using Velocity Script?

You can follow me, then we can DM about it.

Highlighted
Anonymous
Not applicable

Re: How do I modify the date format for a token using Velocity Script?

Thanks Mate