Register Date Selection via clicker and compare date field value with new Date()

Home › Forums › Classic DFFS › Register Date Selection via clicker and compare date field value with new Date()

Viewing 2 reply threads
  • Author
    Posts
    • #25434
      becca
      Participant

        Two-for-one special this time, I want to run code if a date field is changed and if that change is for a date greater than today. I have my nested if’s set up right, but it only registers a change done by text entry to the textbox portion of the date field and the output of getFieldValue(‘datefield’) and new Date() are different so <= doesn’t work in my if.

        How can I 1) register a selection made in the clickDatePicker and 2) format new Date() to match the format of getFieldValue(‘datefield’) (or is there a different way to approach this comparison)?

      • #25460
        Alexander Bautz
        Keymaster

          Hi,
          You can use something like this:

          var currVal = getFieldValue("DateColumn1");
          setInterval(function () {
              var val = getFieldValue("DateColumn1");
              if (val !== currVal) {
                  currVal = val;
                  // Changed - run your code here
                  var now = new Date();
                  var currDate = spjs.utility.getDateFieldAsDateObject("DateColumn1");
                  // Correct hour, minute and second to make a comparison on date only
                  now.setHours(12, 0, 0);
                  currDate.setHours(12, 0, 0);
                  if (currDate > now) {
                      alert("Greater than today");
                  } else {
                      alert("Less than or equal to today");
                  }
              }
          }, 1000);

          Change “DateColumn1” to match your field internal name.

          Alexander

        • #25516
          becca
          Participant

            Works perfectly, thanks.

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