Skip weekends formula

Skip weekends formula

Hello, I am building a database that will allow a user to set a target delivery date and choose a shipping zone. Based off of this information the program will auto populate the "needs to ship on date." My issue is i can not find a formula to add in the extra two days for the weekend if there is a weekend in the middle. This is what I have so far. Thanks in advance for any help.

  1. if (input.Shipping_Zone  !=  "-Select-")
  2. {
  3.     days = ((input.Shipping_Zone).subString(0,1)).toLong();
  4.     if (days  >  5)
  5.     {
  6.         days = (days  +  2);
  7.     }
  8.     input.Must_Ship_On = (input.Target_Delivery_Date).subDay(days);
  9.     if (input.Must_Ship_On.getDayOfWeek()  ==  1)
  10.     {
  11.         input.Must_Ship_On = input.Must_Ship_On.subDay(2);
  12.     }
  13.     else if (input.Must_Ship_On.getDayOfWeek()  ==  7)
  14.     {
  15.         input.Must_Ship_On = input.Must_Ship_On.subDay(1);
  16.     }
  17. }