Populate duration field with subtracting two dates

ServNowDev
Tera Guru
   // Add your code here

    if (current.departure_date && current.return_date) {
        var departureDate = new GlideDateTime(current.departure_date);
        var returnDate = new GlideDateTime(current.return_date);
        var durationCalculated = returnDate.getNumericValue() - departureDate.getNumericValue();
        
		
		current.duration = durationCalculated;

    }

Im getting a NAN for the output, not sure why but i would like to populate the duration of these return and departure dates and place in the duration field. it is of duration type, also im up for changing the type if needed as well.

5 REPLIES 5

Vasu ch
Kilo Sage

Hi @ServNowDev ,

Try using GlideDateTime.subtract(start,end).getDisplayValue();

See the below script for reference

 

Vasuch_0-1699122549761.png

Output:

Vasuch_1-1699122594382.png