6 Replies Latest reply on Nov 2, 2018 4:53 PM by Sanford Whiteman

    Adding days to a date field with Velocity script

    Alan Harris

      I've tried all the techniques I've seen online for adding or subtracting hours / days / months / years to a date using Velocity scripting, but have bee unable to successfully recreate it myself.

       

      I'm using the following email script to take a date in "MM-DD-YYYY" from a Salesforce opportunity date field, and output as "Day of week, Date, Year". For example 11/02/2018 would be outputted as "Friday, November 2, 2018".

       

      #set( $inTimeZone = $date.getTimeZone().getTimeZone('America/Los_Angeles') ) 
      #set( $outTimeZone = $date.getTimeZone().getTimeZone('America/Los_Angeles') ) 
      #set( $locale = $date.getLocale() ) 
      #set( $myDate = $convert.parseDate($OpportunityList.get(0).Auto_Renewal_Date__c,'yyyy-MM-dd',$locale,$inTimeZone) ) 
      ${date.format('EEEE, MMMM dd, yyyy',$myDate,$locale,$outTimeZone)}
      

       

      The script above works, but I'd like to also be able to add either 30 days to the displayed date, or add 1 month. So for example, 11-02-2018 would output as "Sunday, December 2, 2018"

       

      Nothing I've tried has worked so far. Any help would be greatly appreciated.