Skip to main content
Nov 27, 2014 9:18 PM UTC
Question

Velocity and Date Tokens

Hi Nation!

We are working on a velocity script to make a date formatted in a more natural language like "We will expect you on December 13". Unfortunatelly, when I try to use the line 
#set( $mydate = ${convert.parseDate(${lead.mydatetoken},"YYYY-MM-dd")})
The variable $mydate is empty. I realized this has to do with the fact the string is not always YYYY-MM-dd, it can change. I still haven't figured out why, I believe it has to do with the fact that our users have different locales.

My question is... is there a way to get from the actual lead token, in this case ${lead.mydatetoken}, a definitive value regardless of locale? just as you would in other programming languages where you would get a long counting the seconds from midnight January 1st 1970? 

Any help will be very appreciated, thanks!
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Josh_Hill13
Level 10
Nov 29, 2014 4:56 AM UTC
Why can't you use a text my token that has December 13?
Translate
Brennan_McAdam2
Level 4
Nov 29, 2014 2:20 PM UTC
Hi Carlos,

Looks to me as if you are getting the vaue from lead correctly.  However, you should using the .toDate() method (if available). http://stackoverflow.com/questions/22150952/string-to-date-with-convert

Once you have the date in the object, format it with .format().  http://velocity.apache.org/tools/releases/2.0/javadoc/org/apache/velocity/tools/generic/DateTool.html#format(java.lang.String, java.lang.String, java.lang.Object, java.util.Locale, java.util.TimeZone)

Just piecing this together, as I am looking for a test bed for velocity scripts.
Translate
Brennan McAdams