Date Format on Email Script | Community
Skip to main content
November 16, 2015
Solved

Date Format on Email Script

  • November 16, 2015
  • 3 replies
  • 3735 views

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

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

I think I see what you are doing wrong.

You are formatting $current_date

but displaying  $x

Try displaying $current_date

3 replies

November 16, 2015

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.

November 16, 2015

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

November 16, 2015

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

November 16, 2015

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

December 29, 2017

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

SanfordWhiteman
Level 10
December 29, 2017

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

Stijn_Heijthuij
Level 6
November 16, 2015

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.