# Start and End Dates

**URL:** <https://forums.knack.com/t/start-and-end-dates/10182>\
**Category:** Get Answers\
**Created:** [April 5, 2016, 4:59am UTC](https://forums.knack.com/t/start-and-end-dates/10182 "2016-04-05T04:59:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PhilWesley67576](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/philwesley67576/32/157_2.png) [@PhilWesley67576](https://forums.knack.com/u/PhilWesley67576)\
**Post date:** [April 5, 2016, 4:59am UTC](https://forums.knack.com/t/start-and-end-dates/10182/1 "2016-04-05T04:59:48Z")

</div>

I can't figure out how to calculate the duration in a start-date to end-date. Once Calendar options are selected, you have the option for stat and end dates, I ned an auto calculation to workout the duration.

Any ideas?

Thanks

---

<div class="post-metadata">

**Author:** ![SamHansard31662](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@SamHansard31662](https://forums.knack.com/u/SamHansard31662)\
**Post date:** [April 7, 2016, 3:40am UTC](https://forums.knack.com/t/start-and-end-dates/10182/2 "2016-04-07T03:40:31Z")

</div>

$(document).on('knack-view-render.view\_29', function(event, view, data) {

&nbsp; document.getElementById("field\_63").readOnly = true;

&nbsp; $(document).on("change load input click", "#kn-input-field\_60 input", function(){

&nbsp; &nbsp;var startDate = $("#view\_29-field\_60").val().split("/");

&nbsp; &nbsp;var endDate = $("#view\_29-field\_60-to").val().split("/");

&nbsp; &nbsp; console.log(startDate[2]+"/"+startDate[1]+"/"+startDate[0]);

&nbsp; &nbsp; startDate = new Date(startDate[2],startDate[1],startDate[0]);

&nbsp; &nbsp; endDate = new Date(endDate[2],endDate[1],endDate[0]);

&nbsp; &nbsp; var timeDiff = Math.abs(endDate.getTime() - startDate.getTime());

&nbsp;var diffDays = Math.ceil(timeDiff / (1000 \* 3600 \* 24));

&nbsp; &nbsp; console.log(diffDays);

&nbsp; &nbsp; $("#field\_63").val(diffDays);

&nbsp; });

&nbsp;

});

Here's how I did it to output the number of days into a new field, just replace the views and fields as necessary, not really optimized at all but functioning

---

<div class="post-metadata">

**Author:** ![ThibautEgg59867](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@ThibautEgg59867](https://forums.knack.com/u/ThibautEgg59867)\
**Post date:** [April 6, 2016, 10:18pm UTC](https://forums.knack.com/t/start-and-end-dates/10182/3 "2016-04-06T22:18:40Z")

</div>

Same problem.

I need to calculate the duration of calendar events...
