Copy link to clipboard
Copied
I am trying to create a javascript that calculates the total days between Start Date and End Date, while excluding weekends (Saturday and Sunday).
I used the following formula for the date difference:
var sDate1=this.getField("Date2_af_date").value;
var sDate2=this.getField("Date3_af_date").value;
var oDate1 = util.scand("mm/dd/yy", sDate1);
var oDate2 = util.scand("mm/dd/yy", sDate2);
var nDay = 1000 * 60 * 60 * 24;
var eDays=Math.abs(oDate1-oDate2)/nDay+1;
event.value=Math.round(eDays);
Having issues figuring out how to exclude weekends. I'm not familiar with Javascript, so any help is appreciated.
Copy link to clipboard
Copied
There are several ways you can do it.
One would be to use the getDay method of both Date objects to figure out which days they are in the week, and then based on the number of weeks between them calculate how many weekends there are. For example, if the first day is a Monday and the last day is Wednesday and there are 44 days between them then the result is 12: Math.floor(44/7)*2
So you deduct that result from the total to get the new total: 44-12 = 32 non-weekend days
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more