SOLVED

Re: Date Format on Email Script

Go to solution
Anonymous
Not applicable

Date Format on Email Script

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

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: Date Format on Email Script

I think I see what you are doing wrong.

You are formatting $current_date

but displaying  $x

Try displaying $current_date

View solution in original post

10 REPLIES 10
Anonymous
Not applicable

Re: Date Format on Email Script

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.

Anonymous
Not applicable

Re: Date Format on Email Script

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

Anonymous
Not applicable

Re: Date Format on Email Script

Can you show me how you formatted it the second time?  That really should work.

Anonymous
Not applicable

Re: Date Format on Email Script

I think I see what you are doing wrong.

You are formatting $current_date

but displaying  $x

Try displaying $current_date

Anonymous
Not applicable

Re: Date Format on Email Script

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!

Anonymous
Not applicable

Re: Date Format on Email Script

Yep, see below.  It's always helpful to post the final solution... I can't be the only one out there looking!

Anonymous
Not applicable

Re: Date Format on Email Script

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

Anonymous
Not applicable

Re: Date Format on Email Script

I'm trying to change the date to 7 days in the past. what would I need to change?

SanfordWhiteman
Level 10 - Community Moderator

Re: Date Format on Email Script

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).