# Trying to make a function to calculate 5 working days in future

**URL:** <https://forum.kirupa.com/t/trying-to-make-a-function-to-calculate-5-working-days-in-future/186748>\
**Category:** flash\
**Created:** [April 24, 2006, 10:52am UTC](https://forum.kirupa.com/t/trying-to-make-a-function-to-calculate-5-working-days-in-future/186748 "2006-04-24T10:52:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hectors](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/hectors/32/2118_2.png) [@hectors](https://forum.kirupa.com/u/hectors)\
**Post date:** [April 24, 2006, 10:52am UTC](https://forum.kirupa.com/t/trying-to-make-a-function-to-calculate-5-working-days-in-future/186748/1 "2006-04-24T10:52:19Z")

</div>

Hello there, I am trying to write a function that I can pass a date to that will return the value of 5 working days in the future for a delivery.  
I am going about this by creating a bunch of arrays like this

```auto
var weekArr:Array = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", 
"Sun");
var monthDaysArr:Array = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var monthDaysLeapArr:Array = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

```

and then a big function with lots of if statements that starts like this:

```auto
var standardDeliv:Number= 7//number of days for delivery
function checkDeliv(day:String, date:Number, month:String, year:Number):Array{
 if([EMAIL="day!="]day!=[/EMAIL]Sat"|| day!="Sun" && date<=21)
 deliveryArr[0]=day;
 deliveryArr[1]=date+standardDeliv;
 deliveryArr[2]=month;
 deliveryArr[3]=year;
//lots of other if statements to handle other situations below
 }

```

I was wondering if I am going about this the right way or if there is a much simpler way of doing it. I’m not asking anyone to write the code for me (though feel free :)) I’m just after a bit of direction as to how a more experienced Actionscripter would set about this.

Cheers guys,

Hectors

BTW- I am getting the intial date from a PHP file on my server through LoadVars() and I have written the code above on a text editor without Flash so there may be some punctuation errors.

---

<div class="post-metadata">

**Author:** ![mathew\_er](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mathew\_er](https://forum.kirupa.com/u/mathew_er)\
**Post date:** [April 24, 2006, 11:32am UTC](https://forum.kirupa.com/t/trying-to-make-a-function-to-calculate-5-working-days-in-future/186748/2 "2006-04-24T11:32:52Z")

</div>

```auto
var future:Date = new Date(2006, 3, 27);

trace(getWorkingDays(future));
// returns date in month/day format in an array

function getWorkingDays(date:Date):Array {
    var i = 0;
    var days = new Array();
    trace(date.getDay());
    do {
        if (isWorkingDay((date.getDay()+i)%7)) {
            trace(date.getTime()+(86400000*i));
            var returnDate = new Date(date.getTime()+86400000*i);
            trace(returnDate);
            days.push((returnDate.getMonth()+1)+"/"+(returnDate.getDate()));
        }
        i++;
    } while (days.length != 5);
    return days;
}
function isWorkingDay(day:Number):Boolean {
    return (day == 6 || day == 0) ? false : true;
}

```

edit: I forgot one thing… months… just give me a second =)

edit2: done
