I'm trying to write a velocity email script that takes the user's date and subtracts it by a fixed date (promo code expiration date).
Here's my code so far:
#set ($today = $convert.parseDate($date.getDate(), "yyyy-MM-dd")
#set ($promoEnd = $convert.parseDate('2018-02-01', "yyyy-MM-dd"))
#set ($result = $date.difference ($promoEnd, $today).days)
#end
When I test it out in an email, I get this error:
"An error occurred when procesing the email Body! Encountered "#set" near" (followed by my code)
Given that Marketo converts all data types to a string, I think I need to format the dates into a number in order to effectively call the date.difference method - but other than that I'm not sure what's going wrong.
Any help would be appreciated, thanks!
Solved! Go to Solution.
James, please use the syntax highlighter in Advanced Editor when posting code. Otherwise, it can be next to impossible to read. (Highlight as Java as it's the closest to Velocity.)
The direct cause of your error is a simple syntax error: you're missing a closing ) on the first line.
But even if you fix that, it doesn't look like you're going about this the right way...
I updated this seminal blog post with example code for your case: http://blog.teknkl.com/velocity-days-and-weeks/#howlongwillthepromolast
Remember to include the common code block at the top of the post, where you set the time zone as is essential for all datetime work.
I'll look at this later. FYI there is a Jive bug that is causing posts to not show up for all people, thus I missed this until today.
James, please use the syntax highlighter in Advanced Editor when posting code. Otherwise, it can be next to impossible to read. (Highlight as Java as it's the closest to Velocity.)
The direct cause of your error is a simple syntax error: you're missing a closing ) on the first line.
But even if you fix that, it doesn't look like you're going about this the right way...
I updated this seminal blog post with example code for your case: http://blog.teknkl.com/velocity-days-and-weeks/#howlongwillthepromolast
Remember to include the common code block at the top of the post, where you set the time zone as is essential for all datetime work.
Thank you very much! Really impressed with all of this.
I just ran a sample email, but unfortunately I got "The promo has already ended", the else portion of the if statement.
The date in the code itself is later than the date I ran the test, so I think it's having a problem picking up the calEndOfPromo variable.
Let me know if you need any more info, thank you again for all of your help!
Provide the whole token you're currently using, plus add these 2 lines at the end to dump the current dates
calNow: $date.format("yyyy-MM-dd'T'HH:mm:ss Z", $calNow)
calEndOfPromo: $date.format("yyyy-MM-dd'T'HH:mm:ss Z", $calEndOfPromo)