# Unable to take the difference between two dates

edited October 2019 in Problems
Hello all,

I am attempting to take the difference of two dates (in number of days). Thus far I am unable to get anything to show other than 0. Please see my UI field setup below.

I have even tried just pulling in one of the dates with the return type of date with nothing showing up. Does anyone know what I am doing wrong?

I have been trying to do something similar to:
https://community.skuid.com/skuid/topics/calculate-age-with-ui-only-field
but again, with no luck.

Thanks,
M\$

Tagged:

• edited September 2017
Hello Michael,

The return is milliseconds so if you divide by 86400000 (the number of milliseconds in a day) it will give you the number of days. e.g.

({{field_1__c}} - {{field_2__c}})/86400000

Cheers

Damien
• edited September 2017
Hey Thanks for the reply. If you look at my second image you can see I am doing just that. Yet still zeros! I tried taking the difference between TODAY() and one of my dates and got a non-zero result. Perhaps there is a format issue with these dates?
• edited September 2019
Good tip, Damien! But I see that value in Michael's code, as 1000*24*60*60.

Michael, what kind of date values are you comparing? The Floor() function will give you a 0 for anything less than 1 full day difference. I would recommend increasing the decimal places to 1 or 2, removing the Floor() function, and dividing by 1000*60*60 to look at minutes until you see what the formula is giving you.
• edited September 2017
Try another bracket ) at the end.

Alternatively, try it without floor as it shouldn't matter if they are normal date fields
• edited October 2019
Similar to what Mike said, I would add one variable in at a time and see what the result is. So start with {{Service_Start _Date__c}} and see what the result is. If that is what is expected then add the next piece of the equation in and check the result... then the next piece.... etc.... until you find what part of the equation is causing it to return 0.
• edited September 2017
Michael,

Try doing the Floor on just the numerator.

FLOOR( {{Service_Start_Date__c}} - {{Implementation_Manager__r.CS_Start_Date__c}})   /   (1000*24*60*60)

Thanks,

Bill
• edited September 2017
Hi All,

Thanks for the great replies. Following Raymond's advice I have eliminated everything and tried testing the output of a single variable and found that I cannot get any field to display. I have tried numbers and dates with matching return type and still nothing is showing up in the table.

Note that I am attempting to create this UI field within an Aggregate Model (for what it's worth). Each row is an opportunity with a service start date in which I would like to have another field counting days from that date and another (for each opp record). Then on a chart I am plotting the cumulative number of opps by owner.

Is there some sort of trick for getting UI fields to pull in merge fields on an Agg model?

Thanks all.
• edited October 2019
This post is about a different use case, but it includes a lot of tips regarding working with UI only formula fields with agg models. https://community.skuid.com/skuid/topics/using-model-lookup-with-ui-only-field-cant-make-it-work
• edited September 2017
I discovered I am able to achieve what I need using a basic type model. Taking the difference of the two dates as described above worked perfectly. Onward and upward!