AnsweredAssumed Answered

Velocity time formatting - right formatting, wrong date?

Question asked by Phillip Wild on Oct 10, 2018
Latest reply on Oct 11, 2018 by Phillip Wild

Hi everyone


I'm having some trouble with some date formatting through Velocity email scripting. I've used some of Sanford Whiteman's fantastic code, and it's outputting the right formats, but weirdly, the wrong dates. The month always displays as January it seems. I'm sure I'm missing something simple....anyway, here's the code.


When I use an input of "2019-02-23" for the serviceStartDate field on the $abandonedCart_List custom object (there's only one element in that list that I'm using, so there can be no mistake there) I get the output "January 23, 2019". When I use "2019-03-01" for an identical token for "serviceFinishDate" I get "January 1, 2019".  Why?


(Apologies if the code below isn't formatted right, I put it as "Javascript". Hope that's the most appropriate).


## get the size of the list of Abandoned Carts

#set ($listlength = ${abandonedCart_cList.size()}) 

## remove one from the size of the list to reference the right object in the array (arrays start at zero, not 1)

#set( $lastIndex = $math.sub($listlength,1) )

## convert the Service Start Date string to a date

#set( $dateOptions = {  
  "formats" : {  
    "userin" : "yyyy-mm-dd",  
    "userout" : "MMMM d, yyyy"  
  "timezones" : {  
    "userin" : "America/New_York",  
    "userout" : "America/New_York"  
  "locale" : $date.getLocale()  
} )  
#set( $ServiceStartDatelike = $abandonedCart_cList.get($lastIndex).serviceStartDate )  
#set( $ServiceStartDate = $convert.parseDate(  
) ) 

## convert the date to a different format

#set( $ServiceStartDate_formatted = $date.format(  
) )