The New Year is Coming. Don't be "That Company" – Update Your Date!

Casey_Grimes
Level 10
Level 10

gOSzz2q.jpg

As 2016 is coming to a close, a lot of us in marketing are winding down our schedule for the year: sending out holiday cards, making year-end articles, and building flight plans for 2017's initiatives. However, there's one common thing that can trip you up.

Ever looked at a website and wondered if it is still in operation? Maybe a thing or two looked like they could have been updated – and then you notice the copyright notice the in the footer. "2012. Right, this site must be dead. Let's move along."

Because Marketo lacks any sort of year token out of the box, it's very common for email and landing page designers to take the easy way out: simply add the year as plain text – and then as a new year rolls around, their content is stuck without updated values. But we can do better than that: let's set year dates so they're constantly up to date.

Setting Dates in Emails

Since Marketo only has {{system.date}} (which displays the current system date) and {{system.dateTime}} (a standard datetime stamp), we'll need to do two things: format Marketo's current date to your company's current locale, then set up the token to update in perpetuity (so we're not stuck doing this next December). To do this, we'll utilize folder tokens and Velocity scripting.

Need a refresher on folder tokens? Marketo Tokens: Ins and Outs​ and My.Tokens of Affection: Develop a Token Strategy You'll Love​ cover this topic at length. Remember that with something as generic as a year, you'll likely want to put this in the highest folder available.

You'll also want to check what timezone your Marketo instance is on--for instance, app-aba has its internal clock set to Central Standard Time, which means any datetime calculations it performs are going to be set to CST until you tell it otherwise. Now, for a year that may not matter so much to your company, but if you're sending something time-critical around the holidays or are on a very different timezone than your instance, this may not be ideal.

Once you're in your folder, create an Email Script Token  called  {{my.year}} with the following:

#set($timeZoneObject = $date.getCalendar().getTimeZone())

$date.format("yyyy", $date.getDate(), $date.getLocale(), $timeZoneObject.getTimeZone("America/New_York"))

In this case, I'm setting the timezone to EST, but you should put in whatever timezone is relevant to you. From here, any emails you send with {{my.year}} that are inside this folder will correctly render the right year.

Setting Dates in Landing Pages

Thankfully, when it comes to editing dates for landing pages, the process is much more straightforward. Simply open up your template and swap out your typed date for the following:

<script type="text/javascript">

document.write(new Date().getFullYear());

</script>

Because JavaScript calculates dates on the end user's local machine, this means the year that displays will be whatever that person's current year is--whether that's 2016 or 2017, depending on the date.

8213
21
21 Comments
Casey_Grimes
Level 10

Hi Robin,

This should be possible, but there's a couple of precautions to keep in mind here:

  • The Email Script token for calculating year needs to be as high as possible in your folder structure as possible so any emails sent inherit the {{my.year}} token and perform the calculation. If you completely control your Marketo instance, I'd actually recommend putting all of your Marketo folders in one overall folder for this very purpose. Be sure to check inside your email program that you're seeing {{my.year}} show up as inherited.
  • When using this token in particular, the year will not generate if you are doing a generic test email. You must set a specific person for the calculations to trigger and thus populate the year.
Anonymous
Not applicable

Thanks, Courtney. My issue is that the token is in Marketing Activities but the snippet is in the Design Studio. The snippet is not recognizing the my.token. I could've sworn I read in the community that someone had pulled in a custom token into a snippet but I can't figure out how.

Amanda_Thomas6
Level 9

We're trying to do this at the template level, so we enter the code which populates perfectly fine with the email. However, when you view email in browser all you see is the code. We'd love to have a system token for the year only (vs the full date).

SanfordWhiteman
Level 10 - Community Moderator

If Velocity tokens are not working in Web View, open a Support case. This is broken on some Mkto instances, but the correct behavior is for VTL to display as it does in email content.

Amanda_Thomas6
Level 9

Awesome! Thanks, Sandford!

Anna_Blanchet1
Level 4

@Casey_Grimes Tis the season to update copyright years! Question - our landing pages use snippets for disclaimer text. Is there a way to insert the Javascript into a snippet?

SanfordWhiteman
Level 10 - Community Moderator

@Anna_Blanchet1 sure, why not?

 

Anna_Blanchet1
Level 4

Hi @SanfordWhiteman - I was looking to gain clarity on the approach, not just confirmation that it is possible. How would you approach inserting the JS into a snippet? 

SanfordWhiteman
Level 10 - Community Moderator

Well, Snippets have an HTML editor. So insert it the same way you’d insert it into an HTML section on an LP.

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Here's the visual aid on where/how JS could be added to the snippet - 

 

Click HTML > Add JS (within <script> </script> tag) > Hit Apply

Darshil_Shah1_1-1671700406366.png