Velocity time formatting - right formatting, wrong date? | Community
Skip to main content
New Participant
October 11, 2018
Solved

Velocity time formatting - right formatting, wrong date?

  • October 11, 2018
  • 1 reply
  • 2107 views

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( 

  $ServiceStartDatelike, 

  $dateOptions.formats.userin, 

  $dateOptions.locale, 

  $date.getTimeZone().getTimeZone($dateOptions.timezones.userin) 

) )

## convert the date to a different format

#set( $ServiceStartDate_formatted = $date.format( 

  $dateOptions.formats.userout, 

  $ServiceStartDate, 

  $dateOptions.locale, 

  $date.getTimeZone().getTimeZone($dateOptions.timezones.userout) 

) ) 

${ServiceStartDate_formatted} 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

ISO 8601 date is yyyy-MM-dd.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
October 11, 2018

ISO 8601 date is yyyy-MM-dd.

New Participant
October 11, 2018

Works! Thanks so much!