Hi,
I am using a Velocity script to add a date 14 days in the future on an email token Like so:
## Access Velocity's calendar object
#set($x = $date.calendar)
## Format date
#set($current_date = $date.format('default','short'))
## Add 24 hours (hours=int code 10 - see list below)
$x.add(6,14)
## Show result
$x.time
It is working except that the date format is just not cooperating. I've tried a few options, but I only either get a blank or something formatted like so:
Mon Nov 30 08:09:58 CST 2015.
That's horrendous. I'm looking for this format:
Monday, Nov. 30th, 2015.
I'm imagining some sort of string conversion needs to take place. Also, it would probably get quite complicated with the day format (30th, 21st, 2nd, etc), so that's a wish rather than a need.
Any thoughts out there?
Cheers,
Clare
Solved! Go to Solution.
I think I see what you are doing wrong.
You are formatting $current_date
but displaying $x
Try displaying $current_date
Hi Clare,
In Velocity, what approaches it is [$date.full_date]. If you want to take the more customized approach, take a look at this and adjust where you need to.
#set ( $dateObj = $date.toDate("yyyy-MM-dd", $Opportunity.DateField ) )
#set ( $Day = $date.format("d", $dateObj) )
#if ( $Day == "1" || "21" || "31" )
#set ( $!Day = "${DelDay}st" )
#elseif ( $Day == "2" || "22" )
#set ( $!Day = "${DelDay}nd" )
#elseif ( $Day == "3" || "23" )
#set ( $!Day = "${DelDay}rd" )
#else
#set ( $!Day ="${DelDay}th" )
#end
#set ( $Weekday = $date.format("E", $dateObj) )
#set ( $Month = $date.format("MMMMM", $dateObj) )
#set ( $Year = $date.format("yyyy", $dateObj) )
#end
Then just run the order you want. You might need to remove a few M's from the Month variable to get to Nov.
Monday, Nov. 30th, 2015.
${Weekday}, ${Month}. ${Day}, ${Year}.
Let me know if that works for you.
That worked! For reference, here is the final script. Thanks again for the help!
## Access Velocity's calendar object
#set($x = $date.calendar)
## Format date
#set($current_date = $date.full_date)
## Add 24 hours (hours=int code 10 - see list below)
$x.add(6,14)
## Show result
$current_date
I'm trying to change the date to 7 days in the past. what would I need to change?
You should read this post: http://blog.teknkl.com/velocity-days-and-weeks/
If you have additional Velocity questions, please open a new thread (remember, old threads can have only one answer marked Correct, and only by the original poster).
I think you want to use the $date.full_date format for this.
Here is a link to the velocity document I am referencing: DateTool (VelocityTools 2.0-beta4 Documentation)
Its near the top.
That still results in the same formatting above. I've looked through the documentation, but to no avail. I really, really need to get the time out of there at least. It would be important as well to have proper punctuation.
Thanks,
Clare
I think I see what you are doing wrong.
You are formatting $current_date
but displaying $x
Try displaying $current_date
Awesome! Can you send me the final script you are using? Mine isn't actually displaying and wanted to see what I am doing wrong.
Thanks!
Yep, see below. It's always helpful to post the final solution... I can't be the only one out there looking!
Can you show me how you formatted it the second time? That really should work.