I'm hoping someone can help me with this issue.
I have a booking form with two datefield components named 'my_df' & 'my_df2'.
The required function is to calculate the number of days between the two selections and insert the result into a dynamic text field named 'message_txt'.
I have managed to get this function working, however I need the calculation to only include working days (ie. Monday - Friday).
I have disabled Saturday's and Sundays on the calendar itself by using:
Code:
my_df2.disabledDays = [0, 6];
But the calculation still takes Saturday and Sunday into account if, for example, the user selects a Friday - Monday range. (This calculates as 4 days, when it should calculate as 2).
The full code I currently have in place is as follows:
Code:
import mx.controls.*
var my_df:DateField;
calendar = new Object();
calendar.change = function(eventObj){
date1 = my_df.selectedDate;
year = date1.getFullYear();
month = date1.getMonth();
day = date1.getDate();
my_df2.disabledRanges = [{rangeEnd: new Date(year, month, day)}];
my_df2.disabledDays = [0, 6];
}
my_df.addEventListener("change", calendar);
var my_df2:DateField;
calendar2 = new Object();
calendar2.change = function(eventObj){
date2 = my_df2.selectedDate;
}
my_df2.addEventListener("change", calendar2);
function calculateIt(){
totalDays = date2 - date1;
numDays = Math.floor((date2 - date1)/86400000);
trace("totalDays var = " + totalDays);
trace("numDays var = " + numDays);
message_txt.text = " " + numDays + " Days";
}