Populate duration field with subtracting two dates
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 08:59 AM
// 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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2023 11:30 AM
Hi @ServNowDev ,
Try using GlideDateTime.subtract(start,end).getDisplayValue();
See the below script for reference
Output: