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
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
Can you show me how you formatted it the second time? That really should work.
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!
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).