Skip to main content
Level 6
Jan 25, 2024 2:09 PM UTC
Solved

DaysDiff function not giving correct result

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
ParthaSarathy
ParthaSarathyAccepted solution
Community Advisor
Jan 25, 2024 5:05 PM UTC

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 S

4 replies

isahore
Community Advisor
Community Advisor
Jan 25, 2024 4:05 PM UTC

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

Translate
ParthaSarathy
Community Advisor
ParthaSarathyCommunity AdvisorAccepted solution
Community Advisor
Jan 25, 2024 5:05 PM UTC

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 )

 

Translate
~  ParthaSarathy S
Sanjana12Author
Level 6
Jan 25, 2024 5:28 PM UTC

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

Translate
AkshayAnand
Community Advisor
Community Advisor
Jan 29, 2024 11:33 AM UTC

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

Translate