SOLVED

Re: Velocity time formatting - right formatting, wrong date?

Go to solution
Phillip_Wild
Level 10

Velocity time formatting - right formatting, wrong date?

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} 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity time formatting - right formatting, wrong date?

ISO 8601 date is yyyy-MM-dd.

View solution in original post

2 REPLIES 2
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity time formatting - right formatting, wrong date?

ISO 8601 date is yyyy-MM-dd.

Phillip_Wild
Level 10

Re: Velocity time formatting - right formatting, wrong date?

Works! Thanks so much!