Skip to content
Release: Australia · Updated: 2026-03-12 · Official documentation · View source

GlideDuration- Scoped

The GlideDuration class provides methods for working with spans of time known as durations.

GlideDuration objects store the duration as the number of days and time from January 1, 1970, 00:00:00. As a result, the setValue() and getValue() methods use the scoped GlideDateTime object for parameters and return values.

Parent Topic:Server API reference

GlideDuration - GlideDuration()

Instantiates a GlideDuration object.

NameTypeDescription
None  

GlideDuration - GlideDuration(GlideDuration another)

Instantiates a GlideDuration object by cloning the values of the passed in GlideDuration object.

NameTypeDescription
anotherGlideDurationGlideDuration object.
var duration = new GlideDuration('3 12:00:00');
var duration2 = new GlideDuration(duration);
gs.info(duration2.getDisplayValue());

Output:

3 Days 12 Hours

GlideDuration - GlideDuration(Number milliseconds)

Instantiates a GlideDuration object with the specified duration in milliseconds.

NameTypeDescription
millisecondsNumberDuration value.Unit: Milliseconds
var dur = new GlideDuration(60000);
gs.info(dur.getDurationValue());

Output:

00:01:00

GlideDuration - GlideDuration(String displayValue)

Instantiates a GlideDuration object with the specified duration display value.

NameTypeDescription
displayValueStringDuration value.Format: d HH:mm:ss where "d" is number of days.
var duration = new GlideDuration('3 12:00:00');
var duration2 = new GlideDuration('3:00:00');
var answer = duration.add(duration2);
gs.info(answer.getDisplayValue());

Output:

3 Days 15 Hours

GlideDuration - add(GlideDuration duration)

Adds the duration of the specified GlideDuration object to the current GlideDuration object.

NameTypeDescription
durationGlideDurationGlideDuration object that contains the duration value to add to the current GlideDuration object.
TypeDescription
GlideDurationNew GlideDuration object whose duration is the sum of the durations of the two GlideDuration objects.
var duration = new GlideDuration('3 12:00:00');
var duration2 = new GlideDuration('3:00:00');
var answer = duration.add(duration2);
gs.info(answer.getDisplayValue());

Output:

3 Days 15 Hours

GlideDuration - getByFormat(String format)

Returns the duration value in the specified format.

NameTypeDescription
formatStringDuration format.Format: Global date and time field format
TypeDescription
StringCurrent duration in the specified format.
var dur = new GlideDuration('3 22:00:00');
gs.info(dur.getByFormat('HH:mm'));

Output

22:00

GlideDuration - getDayPart()

Returns the number of days.

NameTypeDescription
None  
TypeDescription
NumberNumber of days in the duration.
var dur = new GlideDuration('3 12:00:00');
gs.info(dur.getDayPart());

Output:

3

Scoped GlideDuration - getDisplayValue()

Returns the display value of the duration in number of days, hours, and minutes.

NameTypeDescription
None  
TypeDescription
StringNumber of days, hours, and minutes, such as 2 Days 10 Hours 36 Minutes.Format: Display value: "n" Days "n" Hours "n" Minutes
var dur = new GlideDuration('3 12:00:00');
gs.info(dur.getDisplayValue());

Output:

3 Days 12 Hours

GlideDuration - getDurationValue()

Returns the duration value in "d HH:mm:ss" format.

NameTypeDescription
None  
TypeDescription
StringDuration value. Format: d HH:mm:ss where "d" is number of days.
var dur = new GlideDuration(60000);
gs.info(dur.getDurationValue());

Output:

00:01:00

GlideDuration - getRoundedDayPart()

Returns the rounded number of days. If the time part is more than 12 hours, the return value is rounded up. Otherwise, it is rounded down.

NameTypeDescription
None  
TypeDescription
NumberDay value of the display value rounded.
var dur = new GlideDuration('3 14:00:00');
gs.info(dur.getRoundedDayPart());

Output:

4

GlideDuration - getValue()

Returns the internal date/time value of the current GlideDuration object.

GlideDuration objects store the duration as a date and time from January 1, 1970, 00:00:00.

NameTypeDescription
None  
TypeDescription
StringCurrent duration within the GlideDuration object.Format: YYYY-MM-DD HH:mm:ss
var dur = new GlideDuration('3 12:00:00');
gs.info(dur.getValue());

Output:

1970-01-04 12:00:00

GlideDuration - setDisplayValue(String asDisplayed)

Sets the duration display value.

NameTypeDescription
asDisplayedStringDisplay duration value to set.Format: d HH:mm:ss where "d" is number of days
TypeDescription
None 
var dur = new GlideDuration(); 
dur.setDisplayValue('3 08:00:00');
gs.info(dur.getDisplayValue());

Output:

3 Days 8 Hours

GlideDuration - setValue(Object o)

Sets the internal date/time value of the GlideDuration object.

The method sets the duration value to the difference of the passed in date/time the base date/time value of January 1, 1970, 00:00:00. The passed in date/time object (string) is parsed into a GlideDateTime object.

NameTypeDescription
oObjectDate and time to use as the endpoint for the calculated duration time. Format: YYYY-MM-DD HH:mm:ss
TypeDescription
None 
var dur = new GlideDuration();
dur.setValue('1970-01-05 08:00:00'); // sets internal DateTime value. The String is parsed into a GlideDateTime object.
gs.info(dur.getDisplayValue());

Output:

4 Days 8 Hours

GlideDuration - subtract(GlideDuration duration)

Subtracts the duration of the specified GlideDuration object to the current GlideDuration object.

NameTypeDescription
durationGlideDurationGlideDuration object that contains the duration value to subtract from the current GlideDuration object.
TypeDescription
GlideDurationNew GlideDuration object whose duration contains the result of the subtraction of the duration of the two GlideDuration objects.
var duration = new GlideDuration('3 12:00:00');
var duration2 = new GlideDuration('3:00:00');
var answer = duration.subtract(duration2);
gs.info(answer.getDisplayValue());

Output:

3 Days 9 Hours