Calculate number of days between current date and due date

ChadLee4
Tera Contributor

I am trying to create a calculated value field within a form. The value should be the number of days between the current day and the due date field. "due_date" is a field within the table that I created. Right now there is nothing being displayed.

 

ChadLee4_0-1684430654463.pngChadLee4_1-1684430712027.png

 

1 ACCEPTED SOLUTION

Manmohan K
Tera Sage

Hi @ChadLee4 ,

 

You can use below script

  var todayDate = new GlideDateTime();
  var dueDate = new GlideDateTime(current.due_date);
  var diff = GlideDateTime.subtract(todayDate, dueDate);
  var days = diff.getRoundedDayPart();
  return days;

View solution in original post

1 REPLY 1

Manmohan K
Tera Sage

Hi @ChadLee4 ,

 

You can use below script

  var todayDate = new GlideDateTime();
  var dueDate = new GlideDateTime(current.due_date);
  var diff = GlideDateTime.subtract(todayDate, dueDate);
  var days = diff.getRoundedDayPart();
  return days;