Copy link to clipboard
Copied
I have a very specific calculation I need done. On the top of the form I have an Estimated Closing Date field (called Closing) and an Annual Property Tax Amount field (called Tax). In a field at the bottom of the page- I need to calculate the prorated property taxes. This is calculated by taking the annual property tax amount (Tax) and dividing it by the number of months from 01/01 of this year to the date entered in the estimated closing date (Closing).
I have no clue how to do this. HELP!
Copy link to clipboard
Copied
What do you mean by "number of months", exactly? Full calendar months, no matter their length? In other words, is the result for June 1st the same as for June 30th (5, in this case)?
Copy link to clipboard
Copied
Hello-
So if the estimated closing date is June 1st then it's 5 months but if it's June 30th then we divide by 6 months. If it's closing 10/1 it's 9 months but 10/15 would be 9.5 months. And we often have random dates like closing on 10/26 which would be 9.84 months.
Copy link to clipboard
Copied
So the fraction is the number of days passed divided by the number of days in the last month?
Copy link to clipboard
Copied
Yes 🙂
Copy link to clipboard
Copied
well- to be more detailed. the total calculation I am needing is taking the annual tax amount divided by the number you get by doing the above calculation.
Copy link to clipboard
Copied
or i guess another way you could do it would be to take the annual taxes and divid by 365 days. then calculate the number of days from January 1st to the closing date...
Copy link to clipboard
Copied
Yeah, that's easier to do... You can use this code as the custom calculation script of your field to achieve it (I assumed the date format is "mm/dd/yyyy". If it's not edit it in the code):
var closingDateString = this.getField("Estimated Closing Date").valueAsString;
var taxAmount = Number(this.getField("Annual Property Tax Amount").valueAsString);
if (closingDateString=="") event.value = "";
else {
var closingDate = util.scand("mm/dd/yyyy", closingDateString);
event.value = taxAmount / getDayOfYear(closingDate);
}
function getDayOfYear(d) {
var start = new Date(d.getFullYear(), 0, 0);
var diff = d - start;
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
return day;
}