Changes

Jump to: navigation, search

Counting Business Days between Two Dates

786 bytes added, 16:56, 25 September 2013
no edit summary
To count business days between two dates(''startdate'' and ''enddate''), the following code can be used in a [[Custom Field Type (103): Special – Browser Script|Special Browser script]] field that will populate a [[Custom FieldType: Special – Calculated Value|custom fieldCalculated Value Custom Field]] with the number of business days between two given dates.
In the [[Custom Field Type: Special – Browser Script|Special Browser script]] field you define the function that calculates the difference:
<pre>
function busdatediffbus_date_diff()
{
var frm=document.form1forms[0]; var formatstrformatdate="dd/mm/yyyy@dateformat@"; var start=ConvertDateStr(frm.startdate.value,formatstrformatdate); var end=ConvertDateStr(frm.enddate.value,formatstrformatdate); var diff=datediff(start,end, "D"); var i=0; var busdaybusdays=0; for(i=0;i<diff;i++) { var cdate=dateadd(start,'D',i); if(!isHoliday(cdate)) busday busdays++; }frm.cf_56262.value=busday return busdays;
}
busdatediff();
</pre>
In '''Expression''' section of the [[Custom Field Type: Special – Calculated Value|Calculated Value Custom Field]] you would call the function: bus_date_diff() 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]].    ==See Also==* [[Template_/_Type_Formula#Counting_and_Adding_Business_Days|Using Template Formulas to Count and Add Business Days]]* [[Adding Business Days]] [[Category:Custom Fields]][[Category:Applicant TrackingJavaScript]][[Category:EnhancementsDate Formats]]
8,849
edits

Navigation menu