Jim Clarke

Manipulating a date-time with Velocity

Blog Post created by Jim Clarke on Jun 11, 2015

I wanted to share a simple snippet I didn't find on the community that I thought people may find useful.


When you have a use case for manipulating a date to support a business need (timezone adjustment, formatting, etc), velocity has a pretty simple set of utilities associated with the date object. In this case I'm pulling in two values, one is date-time on the Opportunity the other is string on the Lead which represents US timezones. You can easily modify this timezone for any other criteria as needed this just happened to be the use case I had recently.


Please note you can lean this code out for cleanliness but I wanted to make it easier to read, also this example the client wanted the dates in PST, MST, CST, or EST.

If you want to adjust for daylight savings time or for a global client I would highly recommend performing the logic within CRM, there are several options out there that will provide you a timezone integer that can be put on a contact/lead field making this a lot easier to build. But as you know, sometimes you're asked to do something that has to be done under less than ideal situations.


The key thing that I discovered when I worked on this particular use case was the power of the Calendar utility, I found an awesome resource here that helped greatly.

It would be great to see Marketo add more use cases like this on our community.


Adding Days and Comparing Dates


##Get Appointment Time which is DateTime
#set($appointment = $convert.parseDate(${OpportunityList.get(0).NextPhoneCallAppointment__c}, "yyyy-MM-dd HH:mm:ss"))
#set ($z=$convert.toCalendar( $appointment ))

##Get TimeZone
#set ($studentTimeZone = "MST") ##placeholder in case value is NULL
#set ($studentTimeZone = ${lead.Timezone__c})

##if statement to update student's appointment based off timezone
#if ($studentTimeZone == 'EST')
  #elseif ($studentTimeZone == 'CST')
    #elseif ($studentTimeZone == 'PST')
  #elseif ($studentTimeZone == 'MST')

##display medium format