SOLVED

Re: Set local timezone using Velocity scripts

Go to solution
SanfordWhiteman
Level 10 - Community Moderator

Re: Set local timezone using Velocity scripts

Are you in Sydney?

Anonymous
Not applicable

Re: Set local timezone using Velocity scripts

Yes.

SanfordWhiteman
Level 10 - Community Moderator

Re: Set local timezone using Velocity scripts

K, just checking first! I'm on my phone so can't verify the rest. Let me respond later or tomw. I suspect (well, know) that the stored value has a different offset than what's displayed in SFDC, so you have to account for that.

Victoria_Chu
Level 3

Re: Set local timezone using Velocity scripts

Hi Sanford Whiteman​ I'm looking to create an email velocity script that will display the stored date/time field in the U.S. pacific time zone.

Marketo support says date time field tokens populate with Central time regardless of the location the Marketo Instance is set. This is due to how field values are stored in Marketo.

Would I be able to follow the format of the solution you've provided and swap out any Australia/Sydney reference to US/Pacific? Thank you!

SanfordWhiteman
Level 10 - Community Moderator

Re: Set local timezone using Velocity scripts

This is due to how field values are stored in Marketo.

(It's actually not because of the way they're stored, but the behavior is known in any case.)

Would I be able to follow the format of the solution you've provided and swap out any Australia/Sydney reference to US/Pacific? Thank you!

Yes, the time zone name is

     America/Los_Angeles

Victoria_Chu
Level 3

Re: Set local timezone using Velocity scripts

Thank you Sanford Whiteman​ for the quick response!

This is the velocity script I'm now testing - the particular lead I'm previewing the email at has a create at date/time of Jan 8, 2019 10:22 AM. The velocity script is returning the value as Jan 8, 2019 12:22:00. What did I do wrong?

#set( $inTimeZone = $date.getTimeZone().getTimeZone('America/Los_Angeles') )  

#set( $outTimeZone = $date.getTimeZone().getTimeZone('America/Los_Angeles') )  

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

#set( $myDate = $convert.parseDate(${lead.Created_At},'yyyy-MM-dd HH:mm:ss',$locale,$inTimeZone) )  

${date.format('yyyy-MM-dd HH:mm:ss',$myDate,$locale,$outTimeZone)}

SanfordWhiteman
Level 10 - Community Moderator

Re: Set local timezone using Velocity scripts

Can I ask that you go back and highlight the code using the Advanced Editor's syntax highlighter? That makes it readable.

Also please take the curly braces out from ${lead.Created_At}. Use the simple notation $lead.Created_At. That isn't causing the problem but can cause other problems down the line.

When you simply print the String

$lead.Created_At

in Velocity, do you see

2019-01-08 10:22:00

?

Victoria_Chu
Level 3

Re: Set local timezone using Velocity scripts

#set( $inTimeZone = $date.getTimeZone().getTimeZone('America/Los_Angeles') )  

#set( $outTimeZone = $date.getTimeZone().getTimeZone('America/Los_Angeles') )  

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

#set( $myDate = $convert.parseDate($lead.Created_At,'yyyy-MM-dd HH:mm:ss',$locale,$inTimeZone) )  

${date.format('yyyy-MM-dd HH:mm:ss',$myDate,$locale,$outTimeZone)}

If I simply print the string

$lead.Created_At

In velocity I see

2019-01-08 12:22:00

SanfordWhiteman
Level 10 - Community Moderator

Re: Set local timezone using Velocity scripts

Sorry, the $inTimeZone should be America/Chicago, the $outTimeZone America/Los_Angeles.

Victoria_Chu
Level 3

Re: Set local timezone using Velocity scripts

Thank you it worked beautifully! Curious to your point about removing the {brackets} surrounding the fields. Why would it cause problems in the velocity script? We have that in place for all of our script and want to make sure they continue to function properly.