Email scripts: using dates

Phillip_Wild
Level 10 - Community Advisor

Email scripts: using dates

Hi everyone

Having a bit of trouble formatting dates through email scripting.

Here's my initial code:

<ul>

#foreach ($Tour_Details in ${TravellerServices__cList})

    #if (${Tour_Details.Service_Status__c} == "Confirmed" && ${Tour_Details.ServiceTypeTS__c} == "Tour")

  <li>You took ${Tour_Details.Service_Dossier_Name__c} on ${Tour_Details.Service_Start_Date__c}).

  </li>

    #end

#end

</ul>

This gives me this:

  • You took ATTW on 2013-03-16.
  • You took PAA on 2014-06-30.

Good so far!

Next I tried to format the dates to say "16 March 2013" instead of the current format. So I tried:

#foreach ($Tour_Details in ${TravellerServices__cList})

    #if (${Tour_Details.Service_Status__c} == "Confirmed" && ${Tour_Details.ServiceTypeTS__c} == "Tour")

  <li>You took ${Tour_Details.Service_Dossier_Name__c} on $date.format('dd mmm yyyy' ,${Tour_Details.Service_Start_Date__c}).

  </li>

    #end

#end

</ul>

But this gives me:

  • You took ATTW on $date.format('dd mmm yyyy' ,${Tour_Details.Service_Start_Date__c}).
  • You took PAA on $date.format('dd mmm yyyy' ,${Tour_Details.Service_Start_Date__c}).

Something is obviously wrong. Any ideas?

As a side note, while playing around I tried to use Marketo's example, found here: http://developers.marketo.com/email-scripting/

http://developers.marketo.com/email-scripting/

#set($birthday2015 = "2015-08-07")

##use whenIs to determine how many days away it is

$date.whenIs($birthday).days ##outputs 1

This doesn't seem to work. The output is:

$date.whenIs($birthday).days

It didn't work even when I renamed the variable from $birthday to $birthday2015 in the last line, which I thought might be the error.

Is there something I need to do to "load" the $date functionality in scripting?

Thanks, Phil

$date.whenIs($birthday).days ##outputs 1

2 REPLIES 2
SanfordWhiteman
Level 10 - Community Moderator

Re: Email scripts: using dates

Is there something I need to do to "load" the $date functionality in scripting?

The $date tool is working fine, but your date-like properties aren't Date objects, they're Strings. See here: http://blog.teknkl.com/marketo-vtl-strings-all-the-way-down/.

If you move the post to Products​ I'll answer more there. ('Central is supposed to be for Qs that aren't Marketo-product-specific, though the nomenclature is confusing.)

Phillip_Wild
Level 10 - Community Advisor

Re: Email scripts: using dates

Thanks you Sanford! Believe it or not, I read that post when it came out and it slipped my mind until just now. I'll have another look and let you know if I run into problems.