Copy link to clipboard
Copied
HI! I have a formula that is calculating the difference between two dates and converting it into a decimal, however it is calculating off a 30 day month and I want it to be exact. For example DOB-06/02/17, Date6 is 7/29/19, the calculation I am getting is 26,23, when it should be 25.94. There are 788 days between the two dates, but I need to know the difference in months. Below is my calculation-can anyone help? If I can't make this happen, can I override the calculation and manually enter the correct info? Thank you!!!
(function () {
var sStart = getField("DOB").valueAsString;
var sEnd = getField("Date6").valueAsString;
var dStart, dEnd, diff;
if(sStart && sEnd) {
dStart = util.scand("mm/dd/yyyy", sStart);
dEnd = util.scand("mm/dd/yyyy", sEnd);
diff = dEnd.getTime() - dStart.getTime();
event.value = Math.floor(diff / 864e5)/30;
} else {
event.value = "";
}
})();
Copy link to clipboard
Copied
How did you come to the result of 25.94? What's the logic behind it?
Copy link to clipboard
Copied
Try, the logic is if a child is born on 6/2/17, they wouldn't be 26 months until 8/2/19, then 28 of 31 is actually 90.32. If it isn't possible to get the formula form month to month, how can I change this to custom validation script that would allow me to override it?
Copy link to clipboard
Copied
There are other methods available to the date object beside "getTime". I would look at using the "getFullyear", "getMonth", and "getDate" methods to compute the full number of years, months, and the number of the day within the month. You then only need to get the number of days in the birth month and you should have all the information for your computation.
It would not hurt to add some comments to your code to explain what it is doing.
Unless you are a banker using bank formulas a month does not always have 30 days.
Copy link to clipboard
Copied
Ok, I have been trying to figure out how to write that code, but I am no idea! If you could give me an example or point me to one, that would be great!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now