Calculate the duration between 2 given dates - custom HTML

Confluence User - 25 Mar, 2016

Hi Experts,

I want to calculate duration between two dates: cpo_cpo_date and cpo_cpo_req_date using custom HTML.

Unfortunately no luck when I try to preview, any idea?

APP_date_test-1-20160325142851.jwa

<script type="text/javascript">
$('input[name="cpo_cpo_date"], input[name="cpo_cpo_req_date"]').change( function(){
d1 = $('input[name="cpo_cpo_date"]').datepicker('getDate');
d2 = $('input[name="cpo_cpo_req_date"]').datepicker('getDate');
diff = 0;
if (d1 && d2) {
diff = Math.floor((d2.getTime() - d1.getTime()) / 86400000); // ms per day
}
$('input[name=days]').val(diff);
});
</script>

BR,

Sylwester

 

field;javascript;html

1


28 Mar, 2016
confluenceUser
confluenceUser

i tried ur code, look like u need to put it in as following. u attached the change event to an element tht haven't exist.

<script>
$(document).ready(function(){
    $('input[name="cpo_cpo_date"], input[name="cpo_cpo_req_date"]').change( function(){
          d1 = $('input[name="cpo_cpo_date"]').datepicker('getDate');
          d2 = $('input[name="cpo_cpo_req_date"]').datepicker('getDate');
          diff = 0;
          if (d1 && d2) {
                diff = Math.floor((d2.getTime() - d1.getTime()) / 86400000); // ms per day
          }
          $('input[name=days]').val(diff);
    });
});
</script>
RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print