Beginner velocity scripting | Community
Skip to main content
Liz_Davalos
New Participant
November 30, 2017
Solved

Beginner velocity scripting

  • November 30, 2017
  • 1 reply
  • 5251 views

I'm trying to make a script for email that sets the expiration date for an offer 7 days from the send date. Here's what I have, but I can't seem to piece it together.

## Get a java Calendar

#set($x = $date.calendar)

## Add 24 hours (hours=int code 10 - see list below)

$x.add(10,168)

#set( $inTimeZone = $date.getTimeZone().getTimeZone('America/Los_Angeles') ) 

#set( $outTimeZone = $date.getTimeZone().getTimeZone('America/Los_Angeles') ) 

#set( $locale = $date.getLocale() ) 

#set( $myDate = $convert.parseDate($x.time,'MM-dd-yy HH:mm:ss',$locale,$inTimeZone) ) 

${date.format('MMMM dd, yyyy hh:mm a z',$myDate,$locale,$outTimeZone)} 

Ideally I'd like to format the output date to MMM dd, yyyy hh:ss PST.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

Thank you for this, something still seems to be wrong? This is what shows up what I plug that in the the Marketoemail script area:

"$calNow.add($calConst.DATE,7) Our promo expires 7 days from today, which is ${date.format( $FRIENDLY_24H_DATETIME_WITH_FRIENDLY_TZ, $calNow, $defaultLocale,$defaultTimeZone )} 11:59PM PST"

Sorry, I'm a beginner at velocity scripting and for whatever reason date/time scripts always seem super complicated .


Have you included the common variables (the ones at the top of the blog post)?

1 reply

SanfordWhiteman
New Participant
November 30, 2017

Have you read this blog entry from earlier this week? Velocitips: Switch email content based on day/time

Liz_Davalos
New Participant
November 30, 2017

I didn't see that, and I searched heavily for this answer. Anyway I tried that and nothing prints out. How do I get the date generated to show?

SanfordWhiteman
New Participant
November 30, 2017

Tried what, though?

Also, to be clear about your goal, you aren't really "expiring" anything... you just want to display 7 days from the send time. (Whether the offer is still valid on a technical level sn't something Velocity can control unleas you're also using an expiring URL service.)