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.
Solved! Go to Solution.
Have you included the common variables (the ones at the top of the blog post)?
Have you read this blog entry from earlier this week? Velocitips: Switch email content based on day/time
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?
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.)
I added an example to the blog post that seems to be what you're looking for (scroll to the end).
I assume you don't really want
hh:ss
(12-hour hours:seconds)
but actually
HH:mm
(24-hour hours:minutes) or
hh:mm a
(12-hour hours:minutes AM/PM)
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 .
date/time scripts always seem super complicated .
That's not a bad thing! if they don't seem complicated, you're probably doing something wrong. Most examples are broken because people thought it was easy and they didn't test the edge cases.
Thank you for that solution. That give me a good starting point for other date scripts too and now I have a working expiration date. These emails will be triggered so it is a continuous promotion, the date is just to add some urgency. The trouble I've had elsewhere when trying to figure it out was a lack of real world examples. I've saved your blog and imagine I'll be back to it sometime soon.