Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!
SOLVED

DaysDiff function not giving correct result

Avatar

Level 6

Hi, we have an option variable called lastExportDate and a field called lastModified. When we are trying to find the difference between two values using DaysDiff, we are not getting any result. Can somebody please help out with the Javascript code and the expression to use in additional data?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Sanjana12 ,

Considering your option's Data type is 'Date+time'

In workflow, fetch the option value and store it in variable as below,

 

vars.lastExportDate=getOption('lastExportDate');

 

In Query additional data or in enrichment, add the below expression to fetch the Days difference,

 

DaysDiff(ToDateTime($(vars/@lastExportDate)),@lastModified )

 

ParthaSarathy_0-1706202053579.png

View solution in original post

4 Replies

Avatar

Community Advisor

Hi @Sanjana12,

 

Check that both the fields you are comparing are of the date or datetime data type. If not, the function might not give you correct results or no results at all.

 

BR,

Ishan

Avatar

Correct answer by
Community Advisor

Hi @Sanjana12 ,

Considering your option's Data type is 'Date+time'

In workflow, fetch the option value and store it in variable as below,

 

vars.lastExportDate=getOption('lastExportDate');

 

In Query additional data or in enrichment, add the below expression to fetch the Days difference,

 

DaysDiff(ToDateTime($(vars/@lastExportDate)),@lastModified )

 

ParthaSarathy_0-1706202053579.png

Avatar

Level 6

Is it possible to hardcode the values instead of fetching the option variable value.If so, how to do it?

Avatar

Community Advisor

Hi @Sanjana12 

 

Yes you can also hard code the value as :

DaysDiff(ToDateTime('29/02/2024'),@lastModified )

I would suggest you could keep the code dynamic with @ParthaSarathy suggested code.

 

Thanks

Akshay