SOLVED

How to use FlowBoost to compare a datetime field with ({{system.dateTime}} - 7 days) ?

Go to solution
JayW
Level 2

How to use FlowBoost to compare a datetime field with ({{system.dateTime}} - 7 days) ?

I have a custom field called "Last Email Click Date" which is populated everytime a email click is triggered.

I want to do a check using FlowBoost if this date is a week ago, two weeks ago, one month ago etc so that I can do a time decay of the score accordingly.

 

logic is this.

Date1 = {{system.dateTime}} - 7 days

Date2 = {{system.dateTime}} - 30 days

CheckDate = {{lead.Last Email Click Date}}

 

if (Date1 > Check Date)

TimeDecay = -5;

elseif (Date2 > Check Date)

TimeDecay = -10;

else

TimeDecay = 0;

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: How to use FlowBoost to compare a datetime field with ({{system.dateTime}} - 7 days) ?

 

const timeZone = "America/New York";

let now  = FBUtil.time().tz(timeZone);
let emailClickDate = FBUtil.time({{Lead.Last Email Click Date}}).tz(timeZone);

var diffDays = emailClickDate.diff(now,"days");

 

 

This will set diffDays to the number of days between your Last Email Click Date and today. For example, if Last Email Click Date is 2022-07-07 then today (2022-08-03) diffDays is -27.

 

Then check if diffDays is in certain ranges:

if( diffDays < -30 ) {
  // last email clicked was more than 30 days ago
} else if( diffDays < -7 ) {
  // last email clicked was more than 7 days ago but within the past 30 days
} else if( diffDays < 0 ) {
  // last email clicked was before today but within the past 7 days
}

 

(N.B. In this particular case you could leave off the time zones and get the same result, but it’s best practice to stay time zone-aware.)

View solution in original post

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: How to use FlowBoost to compare a datetime field with ({{system.dateTime}} - 7 days) ?

 

const timeZone = "America/New York";

let now  = FBUtil.time().tz(timeZone);
let emailClickDate = FBUtil.time({{Lead.Last Email Click Date}}).tz(timeZone);

var diffDays = emailClickDate.diff(now,"days");

 

 

This will set diffDays to the number of days between your Last Email Click Date and today. For example, if Last Email Click Date is 2022-07-07 then today (2022-08-03) diffDays is -27.

 

Then check if diffDays is in certain ranges:

if( diffDays < -30 ) {
  // last email clicked was more than 30 days ago
} else if( diffDays < -7 ) {
  // last email clicked was more than 7 days ago but within the past 30 days
} else if( diffDays < 0 ) {
  // last email clicked was before today but within the past 7 days
}

 

(N.B. In this particular case you could leave off the time zones and get the same result, but it’s best practice to stay time zone-aware.)