View Full Version : Jason's Date Input Calendar query

12-17-2012, 02:25 AM
Hi there,

I have used Jason's Date Input Calendar, and need a extra functrion for my form to work.
I have two calendar's, an arrival date and a departure date.
I need to count the number of days between the arrival date and the departure date.
Calendar's are setup as follows:

<td colspan="3">Arrival date:
<script type="text/javascript">// <![CDATA[
DateInput('orderdate1', true, 'DD-MON-YYYY')
// ]]></script>

<td colspan="3">Departure date:
<script type="text/javascript">// <![CDATA[
DateInput('orderdate2', true, 'DD-MON-YYYY')
// ]]></script>

Could you please advice how I can calculate the amount of days between the two dates then place the number of days into a textbox.

Thank you in advance :-)

12-17-2012, 06:49 AM
Here's a function to get the difference between two dates:

function calcDate(date1, date2) {
var one_day=1000*60*60*24;

var date1_ms = date1.getTime();
var date2_ms = date2.getTime();

var difference_ms = date2_ms - date1_ms;

return Math.round(difference_ms/one_day);

So in order to get the date difference, it would be:

document.getElementById('yourTextBox').value = calcDate(this.form.outerdate1.value, this.form.outerdate2.value);

The only issue, may be format of the date, so you may need to change that.

12-21-2012, 02:07 AM
Thank you Bernie, will give it try and let you know if resolved. :-)