Skip to main content

IMPORTANT - Product End of Life Statement - IMPORTANT

Request RE, Survey, and Calendar 1.5 Support Ending December 31, 2020
Contact Kinetic Data Support with Questions
Kinetic Community

Date Time Compare

Import Files
Service Item Date Time
KURL Date Time Compare.rb
Date Time Compare Error Message How to Compare two Date/Time Questions to ensure that one of the Answers is less than another.  An example of this would be if you had a Start Date/Time question and an End Date/Time question.  In this situation you would want to ensure that the Start Date/Time answer is less than the End Date/Time answer.


To accomplish the Date/Time answer comparison you would need to take the following steps:

1)  Add an Event to your Page that runs on beforeSubmit and has a Custom Action.  This event will call a custom function called DateTimeCompare();  Note that you will need to pass your End Date and Start Date questions into this function.  Therefore the syntax would be:  DateTimeCompare('End Date','Start Date');

2)  Add the following to your Custom Header Content (this defines the custom function called in step 1:


//The End_Date and Start_Date values below are variable vales for the End Date and Start Date Questions which are passed to this function
//when the function is called on the Before Submit action.  This means that the only change required to this code is the Alert/error message.
//Note that these variable values can NOT have spaces and therefore the spaces have been replaced with underscores.

function DateTimeCompare(End_Date,Start_Date){

     var endDate=KD.utils.Action.getQuestionValue(End_Date);

     var startDate=KD.utils.Action.getQuestionValue(Start_Date);

     var startDateFinal = new Date(startDate);

     var endDateFinal = new Date(endDate);

// Finally, we check to see start date is greater than the end date.
     if (startDateFinal>endDateFinal)
          // Personalized message to the user that date is not acceptable
          alert(Start_Date+' value must be before ' +End_Date+ ' value.');
          return false;  //A return value of false will stop the submit process

return true;




Once these actions are completed this function will ensure that the Start Date value is Less Than the End Date value.