Due Date Calculator – Needing M-F dates

Forums Requests Due Date Calculator – Needing M-F dates

Viewing 1 reply thread
  • Author
    Posts
    • #33115
      Teresa Harden
      Participant

      Hi, I need some assistance! I have a “calculator” to determine due dates for multiple milestones. The user entered the “need it by” date, tabs out of the form, and the rest of the dates calculate based on “need it by” date minus or plus xx. (Different milestones have different xx date). I do not allow the form to be saved, as the intention is a ‘calculator’.

      Problem is, there is 1 date that I need to fall on the Friday (business day) before, if the date falls on Saturday or Sunday. In the attached file, it’s the red, bigger font field of “CRQ_x0020_Submitted_x0020_by” minus5. If the minus 5 falls on Sat/Sun, I want THAT field to default to Friday before that date.

      Currently I have a heading warning the user that if date falls on Sat/Sun, it must be Friday, but it’s not helping.

      Is this possible?? Thanks to any insight (CODE AS PASTED IN MY JS TAB BELOW with a —>>> in the field I need for the above to happen)

      THANK YOU THANK YOU

      function dateOffsetDays(date, days){
      var d = new Date(date.valueOf());
      var nDate = d.setDate(d.getDate()+days); return new Date(nDate);
      }
      function doCalculateDates(){ var deployDate =
      spjs.utility.getDateFieldAsDateObject(“Deployment_x0020_Date”); // Plus 14 days example
      //var plus14 = dateOffsetDays(deployDate, 14);
      //
      spjs.utility.setDateFieldFromDateObject(“Admins_x0020_Approve_x0020_Deplo” , plus14);
      // Minus 14 days example
      var minus20 = dateOffsetDays(deployDate, -20);
      spjs.utility.setDateFieldFromDateObject(“Deployment_x0020_Plan_x0020_Due_” , minus20);
      var minus15 = dateOffsetDays(deployDate, -15);
      spjs.utility.setDateFieldFromDateObject(“Admins_x0020_Approve_x0020_Deplo” , minus15);
      spjs.utility.setDateFieldFromDateObject(“PPRT_x0020_Details_x0020_Due_x00”, minus15);
      spjs.utility.setDateFieldFromDateObject(“JIRA_x0020_Stories_x0020_Extract”, minus15);
      spjs.utility.setDateFieldFromDateObject(“CRQ_x0020_Submission_x0020_by”, minus15);
      var minus10 = dateOffsetDays(deployDate, -10);
      spjs.utility.setDateFieldFromDateObject(“CRQ_x0020_Approved_x0020_by”, minus10);
      var minus5 = dateOffsetDays(deployDate, -5);

      —>>> spjs.utility.setDateFieldFromDateObject(“CRQ_x0020_Submitted_x0
      020_by”, minus5);

      var plus5 = dateOffsetDays(deployDate, 5);
      spjs.utility.setDateFieldFromDateObject(“Uploaded_x0020_to_x0020_GCPAR_x

      0”, plus5);
      spjs.dffs.doReadOnly([ “Deployment_x0020_Plan_x0020_Due_”, “Admins_x0020_Approve_x0020_Deplo”, “PPRT_x0020_Details_x0020_Due_x00”, “JIRA_x0020_Stories_x0020_Extract”, “CRQ_x0020_Submission_x0020_by”, “CRQ_x0020_Approved_x0020_by”, “CRQ_x0020_Submitted_x0020_by”, “Uploaded_x0020_to_x0020_GCPAR_x0”, “CRQ_x0020_Approval_x0020_by”]);
      // Hide Save / Cancel
      jQuery(‘input[value*=Save]’).hide(); //Bottom jQuery(‘input[value*=Commit]’).hide(); //Bottom
      // Hide SP Ribbon
      jQuery(‘a[id*=”Commit”]’).hide(); //Ribbon jQuery(“#s4-ribbonrow”).css({“display”:”none”}); //Ribbon
      }

      Attachments:
    • #33118
      Alexander Bautz
      Keymaster

      Hi,
      You can use code like this to offset the date back to the previous friday:

      var minus5 = dateOffsetDays(deployDate, -5);
      var day = minus5.getDay();
      console.log(minus5);
      console.log(day);
      var offset = 0;
      if(day === 6){
          // 6 = Saturday
          offset = 1;
      }
      if(day === 0){
          // 0 = Sunday
          offset = 2;
      }
      if(offset > 0){
          minus5.setDate(minus5.getDate() - offset);
      }
      console.log(minus5);

      Alexander

Viewing 1 reply thread
  • You must be logged in to reply to this topic.