Avatar

Correct answer by
Employee Advisor

You need to change that string into a date before you evaluate it in the loop. What is the format of the current string?

 

Inside your for loop do something like this.

Option 1 - using vanilla JS (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)

const myDate = Date.parse(new Date(result.@mailDate));

//then

If(myDate > date2){}

 

Option 2 - using ACC Date function

const myDate = formatDate(result.@mailDate, "%4Y/%2M/%2D")

//then

If(myDate > date2){}

https://experienceleague.adobe.com/developer/campaign-api/api/f-formatDate.html 

 

Option 3 - using moment JS (be aware library still works although it is not being investing in anymore, but it still makes it easier). This helped me when I was doing advanced date manipulation 100+ lines of JS.

https://blog.floriancourgey.com/2018/10/use-javascript-libraries-in-adobe-campaign/ 

 

I've done all 3. Which ever fits your context the best is the right one to use.

View solution in original post