SOLVED

Velocity Script Issue

Go to solution
Ashley_D_Innoce
Level 2

I am using this script to give an expiration date that is one week after an email is sent. I can't figure out how to add the "th, nd, st etc" to the date. For example, August 20th instead of August 20. I am having a hard time figuring out how to do this, any help would be appreciated.

#set($dateInSevenDays = $date.calendar)

$dateInSevenDays.add(10,168)

$date.format('EEEE, MMMM d',$dateInSevenDays.time)

1 ACCEPTED SOLUTION
SanfordWhiteman
Level 10 - Community Moderator

Exactly like so:

#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/New_York") )

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

#set( $calNow = $date.getCalendar() )

#set( $ret = $calNow.setTimeZone($defaultTimeZone) )

#set( $calConst = $field.in($calNow) )

#set( $ISO8601 = "yyyy-MM-dd'T'HH:mm:ss" )

#set( $ISO8601DateOnly = "yyyy-MM-dd" )

#define( $enUSDayOrdinalIndicators )

1st,2nd,3rd,4th,5th,6th,7th,8th,9th,10th,11th,12th,13th,14th,15th,16th,17th,18th,19th,20th,21st,22nd,23rd,24th,25th,26th,27th,28th,29th,30th,31st

#end

#set( $indicatorList = $enUSDayOrdinalIndicators.toString().trim().split(",?\d+") )

Today with a friendly ordinal indicator is

${date.format(

  "EEEE, MMMM d'${indicatorList[$calNow.get($calConst.DAY_OF_MONTH)]}'",

  $calNow,

  $defaultLocale,

  $defaultTimeZone

)}

Here I'm displaying the current date using the ordinal indicator.  You can see elsewhere in the post how to add a certain number of days, and simply use that approach with the $date.format() shown here.  (Note you always must set a timezone or half the world will have errors.) 

View solution in original post

14 REPLIES 14