setDate based on another Date and time field

Home Forums Classic DFFS setDate based on another Date and time field

Viewing 2 reply threads
  • Author
    Posts
    • #32507
      Steve
      Participant

        Hello Alex,
        your help would be very appreciated, I’m quite lost even this issue looks so simple.
        1. I have a date and time column (just date) – ‘positiveSince’
        2. I have another date and time column (just date) – ‘positiveTo’

        I need to get a date based on user’s input from ‘positiveSince’ column and with a rule to trigger a custom function to copy this date and add 14 days forth.

        I’ve tried something like this and it’s working until I choose 31st December, it adds 14 days, so the output is 31+14 = 45. 12. 2020 (for example).
        The output should be logical – 14th January 2021 (14. 1. 2021).

        
        
        function endOfQuarantine() {
            let d = spjs.utility.getDateFieldAsDateObject('positiveSince');
            let den = d.getDate()+14;
            let mesic = d.getMonth()+1;
            let rok = d.getFullYear();
        
        console.log(den +". "+ mesic + ". "+rok);
        }

        I’d be glad if you can help me to figure it out.

        Steo

        • This topic was modified 3 years, 10 months ago by Steve.
      • #32510
        Steve
        Participant

          It looks like I got it working:

          
          
          function endOfQuarantine() {
              let d = spjs.utility.getDateFieldAsDateObject('positiveSince');
              let dd = new Date(d);
              dd.setDate(dd.getDate()+14);
              let day = dd.getDate();
              let month = dd.getMonth()+1;
              let year = dd.getFullYear();
          
          let finalDate = (day +". "+ month + ". "+year);
          setFieldValue('positiveTo',finalDate);
          }
        • #32513
          Alexander Bautz
          Keymaster

            I’m glad you figured it out.

            Alexander

        Viewing 2 reply threads
        • You must be logged in to reply to this topic.