SOLVED

Reformatting system.dateTime

Go to solution
tommernagh1
Level 2

Last Interesting Moment

I am creating a couple of emails in a flow and would like to bring through a datestamp at a certain point in the flow for use as a token in one of the emails. We are using form fill as the trigger and so I have tried using the ‘Last Interesting Moment Date’ token but it keeps pulling the right date but the wrong time (usually off by a couple of hours either way). Does anyone know why this is and is there any way of fixing this or editing the code in the email so that it brings through the correct date/time? Also as a follow up question is there a way to re-format the date/time? 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Reformatting system.dateTime


Is there any problem with trying to re-format the system datetime? 

Only the same problem there is trying to access any non-Velocity tokens in Velocity.

 

You’re using a syntax that doesn’t exist — but there’s also no reason to try to use that token! Velocity has its own representation of the current date.

#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/New_York") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
$date.format("EEE, MMM, d, yyyy HH:mm", $calNow, $defaultLocale, $defaultTimeZone )

 

View solution in original post

11 REPLIES 11
jsiebert
Level 5

Re: Last Interesting Moment

For your first question, I have never had this issue and can't find anything online. But I wanted to put in my 0.02c 🙂 

 

In this situation, I'd rather use a custom string field with a flow step to change the data value to the {{system.datetime}} token. I'm not sure what your instance looks like, but we use interesting moments in a lot of different campaigns. Having a dedicated field for the flow would make me sleep better at night than using Last Interesting Moment Date.

 

Lastly, you can use Velocity to change your date/time. Note that I am not using Last Interesting Moment Date, so I'm unsure what Velocity can pull in terms of Interesting Moments. If you're interested in creating a custom field, I've actually shared my the code that I use on Marketing Nation!

 

Jack Siebert
tommernagh1
Level 2

Re: Last Interesting Moment

Thanks! The datetime is working brilliantly, I’m now struggling to adjust the formatting. 

    

<span style="font-size: 12px;"><strong>Sent:&nbsp;<span style="color: #000000; font-family: arial, helvetica, sans-serif; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 300; letter-spacing: normal; orphans: 2; text-align: left; text-indent:

0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: #ffffff; float: none; display: inline !important;">{{system.dateTime}}</span></strong></span>

 

I am a complete novice when it comes to coding. I have looked at the code for my email template and above is the section which references system.dateTime. Instead of the format YYYY-MM-DD hh:mm:ss I would like Day, Month DD YYYY hh:mm. Is this something that you can help with? 

jsiebert
Level 5

Re: Last Interesting Moment

@tommernagh1  You should create a new velocity script token and use the new timestamp field that you created in your velocity script that I posted in the previously linked thread. Here it is below too! 

 

 

#set( $inTimeZone = $date.getTimeZone().getTimeZone('America/New_York') ) 

#set( $outTimeZone = $date.getTimeZone().getTimeZone('America/New_York') ) 

#set( $locale = $date.getLocale() ) 

#set( $myDate = $convert.parseDate(${lead.Your Token Here},'yyyy-MM-dd',$locale,$inTimeZone) ) 

${date.format('MMMM dd, yyyy',$myDate,$locale,$outTimeZone)} 

 

 

This script will only output your datetime field as MM DD, YYYY. I believe if you wanted the day of the week, you'd format it like this, according to what I've seen online:

$date.format('EEE, MMM d, yyyy', $myDate,$locale,$outTimeZone)}

I haven't had the time to test this in my instance though 🙂 

Jack Siebert
tommernagh1
Level 2

Reformatting system.dateTime

Thanks for the help so far. I have inputted the script below and am currently getting ${date.format('EEE, MMM, d, yyyy',$myDate,$locale,$outTimeZone)} as the output. I am still looking for the re-formatted {{system.dateTime}} to reflect EEE, MMM, d, yyyy. Is there any problem with trying to re-format the system datetime? 

 

#set( $inTimeZone = $date.getTimeZone().getTimeZone('United Kingdom/London') )

#set( $outTimeZone = $date.getTimeZone().getTimeZone('United Kingdom/London') )

#set( $locale = $date.getLocale() )

#set( $myDate = $convert.parseDate(${system.dateTime},'yyyy-MM-dd',$locale,$inTimeZone) )

${date.format('EEE, MMM, d, yyyy',$myDate,$locale,$outTimeZone)}
SanfordWhiteman
Level 10 - Community Moderator

Re: Reformatting system.dateTime


Is there any problem with trying to re-format the system datetime? 

Only the same problem there is trying to access any non-Velocity tokens in Velocity.

 

You’re using a syntax that doesn’t exist — but there’s also no reason to try to use that token! Velocity has its own representation of the current date.

#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/New_York") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
$date.format("EEE, MMM, d, yyyy HH:mm", $calNow, $defaultLocale, $defaultTimeZone )

 

tommernagh1
Level 2

Re: Reformatting system.dateTime

Thank you very much, works perfectly!

tommernagh1
Level 2

Re: Reformatting system.dateTime

A follow up on the above question! I am trying to record the system-datetime for different email delivery steps in my Marketo flow and then use these in subsequent emails. I currently use a formfill and then have built some email follow up assets accordingly. I would like to use the email delivered time of my previous email in the follow up that I am building.

May be able to minus from the system datetime according to the time delay I have between first email and follow up?

SanfordWhiteman
Level 10 - Community Moderator

Re: Reformatting system.dateTime

You can get the difference between two Date objects with $date.diff.

tommernagh1
Level 2

Re: Reformatting system.dateTime

How do I turn ‘email delivered’ into an object I can use in the email templates? Either that works as a solution or I minus the delay between first and second email(e.g. 7 days) from my current system.datetime and have it present in the below format?
EEE, MMM, d, yyyy HH:mm