Is there anyway to calculate date range from today until selected date?

Confluence User - 23 Jun, 2021

Currently I am trying to use hash variable in my javascript to calculate the date range from the selected day I picked but it doesn't work, here are my code

<script type="text/javascript">
$(input[name="start"]').change( function(){
      d1 = $('input[name="start"]').datepicker('getDate');
      d2 = #date.yyyy-MM-dd#;
      diff = 0;
      if (d1 && d2) {
            diff = Math.floor((d2.getTime() - d1.getTime()) / 86400000); // ms per day
      }
      $('input[name=testing]').val(diff);
});
</script>

so I wonder is there other approach for getting the date range?

datetime;javascript

2


24 Jun, 2021
confluenceUser
1
confluenceUser

Dont use 

d2 = #date.yyyy-MM-dd#;

Use

d2 = $('input[name="start"]').datepicker('getDate');



because hash variable can only be parsed at server side (once when you load the form from server)

I think you want it to run everytime "start" value is changed.

24 Jun, 2021
confluenceUser
confluenceUser

It works, the problem is if I set d2 datepicker to readonly, the script will become no function and I don't want the user to manipulate the date of current day.

RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print