AnsweredAssumed Answered

Copying the DATE portion of a datetime control into the DATE portion of another datetime control

Question asked by jr204 on Nov 18, 2015
Latest reply on Nov 19, 2015 by jr204

I'm having some difficulty grasping how datetime values from Nintex are stored/manipulated as javascript variables.  I'll begin by explaining what I'm trying to accomplish, as it seems it should be pretty easy.  I'm not very experienced with javascript but I've tried reworking multiple suggestions on these forums to fit my problem and I continue to run into issues.

 

I am working on a form to request parking validation.  There are two controls on the form that I'm concerned with, an arrival datetime and departure datetime.  What I'd like to do is when the DATE of one of these controls is changed, I'd like for that date to copy into the other control.  The time portion should not change.  Additionally, I want to be able to calculate the difference between these two times via a calculated field, which is currently working properly when the dates are manually selected from the datepicker.

 

The code snippet below is the closest I've been able to get.  When the arrival time is changed, the empty date constructor sets dateEntered to the current date, and the current date properly copies into the second control on the form.  As desired, the Time fields do not appear to be affected.  However, I cannot figure out how to create the date object with the value from the arrival time control so it behaves in a similar fashion.  When I try adding additional lines of code to store the date, the value stops copying altogether, so I'm having difficulty determining where the breakdown is and if it's a syntax error or an issue with how the date is formatted.

 

// Set up an on-change event for the Departing date box to copy the date value to Returning
var dateEntered = new Date();
var inpArriving = NWF$("#" + v_arrTime);

 

inpArriving.change(function()
{
  //var dateEntered = NWF$("#" + v_arrTime).val();
  NWF$("#" + v_depTime).val((dateEntered.getMonth()+1) + "/" + dateEntered.getDate() + "/" + dateEntered.getFullYear());
  alert("TEST");
});

 

In the above code, if I swap the comments on the var dateEntered assignments, the alert does not come through.  I've seen the same operation in numerous posts so I don't believe this is a syntax error but is more likely an issue with my lack of understanding regarding how the dates are stored and how they need to be manipulated to properly populate the control on the form.

 

Could anyone help me to understand what I need to do to implement this on-change function and achieve the desired results?  Or if you have a more simple solution/approach you'd like to suggest, please let me know.  I'm open to suggestions   Thanks!!

Outcomes