Tips and Tricks: Marketo Date Arithmetic

In the two plus years I’ve been using Marketo I’ve had a lot of difficult, and sometimes impossible sounding, requests. One great thing about Marketo is, there’s almost always a way to get it done. In this short blog post I’m going to show you how I tackled three different date related challenges.

Basic Date Arithmetic in Flow Steps

There are many scenarios where you may want to trigger an event or email after a certain number of days. For example, you have a SaaS app and a person signs up for a free trial which expires in 90 days, and you want to send them a survey when the trial expires; or you want to put leads into a nurture for a specific time period. Many are surprised by how simply this problem is solved. In a flow step you can add a number to a date value and store it in a new date. Using a data value change, you put something like this in your new value:

{{lead.BeginDate}} + 90 days

Go ahead, try it and see how easily this can be used in your programs.

Date Arithmetic in Email Script Tokens

When Marketo introduced Email Script Tokens, there was much celebration with anyone who’s done any programing and always wanted a little more from Marketo! You can do a lot with Email Script tokens and I’m only going to touch on one small thing you can do related to dates. If you have any programing or scripting experience, you should follow what’s going on (and if not, feel free to reach out with any questions).

Taking our SaaS trial example, let’s say you want to send reminders to people when the trial is ending and let’s make it even more complicated and you want to send them this reminder the next time they login to your app (via a trigger you setup). This can happen at any time and you don’t know when, but you want to say something like this in the email “Hi Jane, Thanks for using our app, we hope you love it and if you want to continue you need to sign up for a paid plan in the next 8 days before your trial ends.” That “8 days” is something that a lot of people struggle with how to get. Using an Email Script token, it’s pretty simple. You know when they signed up and you know how long your free trial is, so you can know at any given time how many days they have left, taking that and plugging it into this script will give you the days:

#set($testDateFuture = r $convert.parseDate(${lead.ExpirationDate},'yyyy-MM-dd'))r#set($daysDifference = r $date.difference($date,$testDateFuture))r$daysDifference.getDays()r

This example uses the current date for one of the dates, but you can use any two dates.

When working with dates in Email Script Tokens, always be sure to use the parseDate first on any fields to make sure you have a valid date object to work with. Also, make sure you know the basics of Email Script Tokens by reviewing this article from Marketo.

Using Multiple Date Filters to Pinpoint a Date Period

Using our SaaS example for the last time, let’s say you want to send your customers an email 180 days after they signed up, but when you started the Trial program months ago, you did not put them into a nurture program. Don’t worry, you can use two smart list filters to pinpoint any date period.

The date math used in the first example above doesn’t work in batch smart lists (there are some date math options in triggered campaigns) and when setting up a date filter there isn’t an option for “exactly 180 days ago.” What you can do is put in two filters: One for “in the past 180 days” and one for “in the past before 179 days” and have it use all filters (1 and 2). This will return a list of leads with that date exactly 180 days ago.

Here’s an example using the Acquisition Date field:

Bottom Line

Some of the solutions above can be found in the Marketing Nation Community discussions and product docs, and others can be found through trial and error, or by selecting a great team like Digital Pi to lean on for help. Sometimes it takes a while to find the solution, but don’t give up, just keep looking and don’t be afraid to try something just because you’re not sure if it will work.

Knowledge is a work-in-process, so please let me know if you have different (better?) ways of solving similar issues.

Here are some additional resources related to the topics above:
Marketo Email script Token
Apache Comparison Date Tool

Your marketing technology experts.

At Digital Pi, we use technology to connect revenue to marketing efforts. We fuse marketing strategies, processes, data and applications to make marketing technology solutions work for clients' businesses.

Learn More
Share this resource

Cookies help us keep the site running smoothly and inform some of our advertising, but if you’d like to make adjustments, you can visit our Cookie Notice page for more information.