Beginner velocity scripting | Community
Skip to main content
Liz_Davalos
Level 4
Nov 30, 2017 10:47 PM UTC
Solved

Beginner velocity scripting

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.
SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
Dec 1, 2017 6:23 PM UTC

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)?

8 replies

SanfordWhiteman
Level 10
Nov 30, 2017 10:52 PM UTC

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

Translate
Liz_Davalos
Level 4
Nov 30, 2017 11:15 PM UTC

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?

Translate
SanfordWhiteman
Level 10
Nov 30, 2017 11:36 PM UTC

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.)

Translate