SOLVED

How to reformat date Token field as full date?

Go to solution
Anonymous
Not applicable

Re: How to reformat date Token field as full date?

The corresponding field was checked.

SanfordWhiteman
Level 10 - Community Moderator

Re: How to reformat date Token field as full date?

Let's check to see what the actual name of the field is in Velocity.  You've said it was Lead.WarrantyExpirationDate.  If you start a new Email Script token (just to leave the real one alone), check the field, and drag the field into the left pane, what shows up?

Anonymous
Not applicable

Re: How to reformat date Token field as full date?

The "W" is lower case when I drag the field over in the test token. I changed it to lower case in the actual token and IT WORKED!!!

THANK YOU SO MUCH!!!!!

SanfordWhiteman
Level 10 - Community Moderator

Re: How to reformat date Token field as full date?

Great. Pls mark my answer with the code as Correct for future searches.

As you can see, there are several moving parts to date parsing and formatting, but once you have covered every point and presented it to the machine, there will (nearly) always be a solution. The fundamental problem is one of human communication vs. machine: machines either make zero assumptions or wrong assumptions about the meaning of times and dates, while people frequently exchange shorthand, like leaving off "am" or "pm" or using fuzzy terms like "next Tuesday" to which the listener unconsciously adds other context to make sense (although that can cause occasional problems in the real world, too).

If you're ever interviewing developers (however unlikely this may be!) and someone says dates/locales/timezones are easy, don't hire them, since they're lying about their experience!

Anonymous
Not applicable

Re: How to reformat date Token field as full date?

I marked your Reply with the code as the correct answer. However, the only correction would be making Warranty lower case in your code. Thanks for teaching me that It's important to drag and drop the date field from the list on the right into the code to ensure it is correct.

Justin_Cooperm2
Level 10

Re: How to reformat date Token field as full date?

If you want a US-formatted date (ex: "9/22/2016") for pacific time, here you go:

#set( $myDate = $date.getSystemDate() )

#set( $calendarObj = $convert.toCalendar($myDate) )

## Change Time Zone to Pacific (System Time is Central)

$calendarObj.add(10,-2)

#set( $output = $date.format('M/d/yyyy', $calendarObj ) )

${output}

Anonymous
Not applicable

Re: How to reformat date Token field as full date?

Thanks, this works for me too