Unable to take the difference between two dates

  • 1
  • Problem
  • Updated 1 year ago
  • Solved
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$
Photo of Michael Schniepp

Michael Schniepp

  • 1,808 Points 1k badge 2x thumb

Posted 1 year ago

  • 1
Photo of Damien Murray

Damien Murray

  • 474 Points 250 badge 2x thumb
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)
Photo of Michael Schniepp

Michael Schniepp

  • 1,808 Points 1k badge 2x thumb
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?
Photo of Damien Murray

Damien Murray

  • 474 Points 250 badge 2x thumb
Try another bracket ) at the end.

Alternatively, try it without floor as it shouldn't matter if they are normal date fields
(Edited)
Photo of Mike Dwyer

Mike Dwyer

  • 3,390 Points 3k badge 2x thumb
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.
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
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.
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
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
Photo of Michael Schniepp

Michael Schniepp

  • 1,808 Points 1k badge 2x thumb
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. 
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
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/top...
Photo of Michael Schniepp

Michael Schniepp

  • 1,808 Points 1k badge 2x thumb
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!