To count subtract business days between two dates (''startdate'' and ''enddate'')from a given date, the following code can be used in a [[Custom Field Type: Special – Browser Script|Special Browser script]] field that will populate a [[Custom Field Type: Special – Calculated Value|Calculated Value Custom Field]] with the number of business days between two given datesnew date.
In the [[Custom Field Type: Special – Browser Script|Special Browser script]] field you define the function that calculates subtracts the difference:a number of days from a given date
<pre>
function bus_date_diffbus_date_subtract()
{
var frm=document.forms[0];
var formatdateformatstr="@dateformat@dd/mm/yyyy"; var start=ConvertDateStr(frm.startdate.value,formatdate); var end=ConvertDateStr(frm.enddate.value,formatdate); var diff=datediff(start,end, "D"formatstr); var i=0; var busdayssub=0-5; for(i=0-1;i<diff>sub;i++--)
{
var cdate=dateadd(start,'D',i);
if(!isHoliday(cdate))
busdays++ sub--;
}
return busdaysdocument.frmevent.cf_1742956 .value=cdate;
}
</pre>
In '''Expression''' section of the [[Custom Field Type: Special – Calculated Value|Calculated Value Custom Field]] you would call the function:
bus_date_diff(bus_date_subtract)
Note: The function definition can be changed to accept parameters (fields containing dates) that are passed at the time of calling the function from any [[Custom Field Type: Special – Calculated Value|Calculated Value Custom Field]].
[[Category:Custom Fields]][[Category:JavaScript]]