Formatting / Subtracting Date - Velocity stopped working | Community
Skip to main content
March 28, 2017
Question

Formatting / Subtracting Date - Velocity stopped working

  • March 28, 2017
  • 1 reply
  • 3090 views

I have a Velocity script where I use DateTool and ComparisonDateTool to find the difference between today and the day a lead started a trial.  It worked magically one day.  And the next day it didn't.  The value holding the start day of the trial would no longer convert into the proper Date Object thus the ComparisonDate difference() would not work. 

There were no changes to the field or our Marketo that I was aware of.  Anyone have any thoughts?  Snippet below

#set ($today = $date.getDate())

#set ($start = $date.format(${OpportunityList.get(0).StartDate__c}))

#set ($diff = $date.difference($start, $today).days)

z${today} | ${start} | ${diff}

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

1 reply

SanfordWhiteman
Level 10
March 28, 2017

You'll need to provide more information about the failure.  Is StartDate__c a string value to begin with, or an actual Date object? If a string, what's the exact format?

Fundamentally $date.format() isn't the way to go about creating date objects for comparison, since it is designed for output (Date-like String → Date → Date-like String).  You want a Date object here, not its default string representation.

March 29, 2017

StartDate__c outputs "2017-03-01" and is a Date field from SFDC.  But I don't think its get read as a Velocity Date Object.

I've tried setting $start by using $date.toDate() and $convert.parseDate()to achieve the proper conversion, but it comes back empty.