---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideDuration - Scoped

# GlideDuration - Scoped {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read

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.

## GlideDuration - GlideDuration() {#ariaid-title2}

Instantiates a GlideDuration object.
{#r_ScopedGlideDurationGlideDuration__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 1. Parameters]

{#r_ScopedGlideDurationGlideDuration__table_vy2_525_jq}

## GlideDuration - GlideDuration(GlideDuration another) {#ariaid-title3}

Instantiates a GlideDuration object by cloning the values of the passed in
GlideDuration object.
{#r_ScopedGlideDurationGlideDuration_GlideDuration__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| another | GlideDuration | GlideDuration object. |
[Table 2. Parameters]

{#r_ScopedGlideDurationGlideDuration_GlideDuration__table_vy2_525_jq}  

    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) {#ariaid-title4}

Instantiates a GlideDuration object with the specified duration in milliseconds.
{#r_ScopedGlideDurationGlideDuration_Number__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| milliseconds | Number | Duration value. Unit: Milliseconds |
[Table 3. Parameters]

{#r_ScopedGlideDurationGlideDuration_Number__table_vy2_525_jq}  

    var dur = new GlideDuration(60000);
    gs.info(dur.getDurationValue());

Output:

    00:01:00

## GlideDuration - GlideDuration(String displayValue) {#ariaid-title5}

Instantiates a GlideDuration object with the specified duration display
value.
{#r_ScopedGlideDurationGlideDuration_String__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| displayValue | String | Duration value. Format: d HH:mm:ss where "d" is number of days. |
[Table 4. Parameters]

{#r_ScopedGlideDurationGlideDuration_String__table_vy2_525_jq}  

    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) {#ariaid-title6}

Adds the duration of the specified GlideDuration object to the current GlideDuration
object.
{#r_ScopedGlideDurationAdd_GlideDuration__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| duration | GlideDuration | GlideDuration object that contains the duration value to add to the current GlideDuration object. |
[Table 5. Parameters]

{#r_ScopedGlideDurationAdd_GlideDuration__table_vy2_525_jq} {#r_ScopedGlideDurationAdd_GlideDuration__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| GlideDuration | New GlideDuration object whose duration is the sum of the durations of the two GlideDuration objects. |
[Table 6. Returns]

{#r_ScopedGlideDurationAdd_GlideDuration__table_qpt_3f5_jq}  

    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) {#ariaid-title7}

Returns the duration value in the specified format.
{#r_ScopedGlideDurationGetByFormat_String__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| format | String | Duration format. Format: [Global date and time field format](https://www.servicenow.com/docs/access?context=r_FormatDateAndTimeFields&version=xanadu&pubname=xanadu-platform-administration&ft:locale=en-US) |
[Table 7. Parameters]

{#r_ScopedGlideDurationGetByFormat_String__table_vy2_525_jq} {#r_ScopedGlideDurationGetByFormat_String__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Current duration in the specified format. |
[Table 8. Returns]

{#r_ScopedGlideDurationGetByFormat_String__table_qpt_3f5_jq}  

    var dur = new GlideDuration('3 22:00:00');
    gs.info(dur.getByFormat('HH:mm'));

Output

    22:00

## GlideDuration - getDayPart() {#ariaid-title8}

Returns the number of days.
{#r_ScopedGlideDurationGetDayPart__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 9. Parameters]

{#r_ScopedGlideDurationGetDayPart__table_vy2_525_jq} {#r_ScopedGlideDurationGetDayPart__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| Number | Number of days in the duration. |
[Table 10. Returns]

{#r_ScopedGlideDurationGetDayPart__table_qpt_3f5_jq}  

    var dur = new GlideDuration('3 12:00:00');
    gs.info(dur.getDayPart());

Output:

    3

## Scoped GlideDuration - getDisplayValue() {#ariaid-title9}

Returns the display value of the duration in number of days, hours, and
minutes.
{#r_ScopedGlideDurationGetDisplayValue__table_vy2_565_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 11. Parameters]

{#r_ScopedGlideDurationGetDisplayValue__table_vy2_565_jq} {#r_ScopedGlideDurationGetDisplayValue__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Number of days, hours, and minutes, such as 2 Days 10 Hours 36 Minutes. Format: Display value: "n" Days "n" Hours "n" Minutes |
[Table 12. Returns]

{#r_ScopedGlideDurationGetDisplayValue__table_qpt_3f5_jq}  

    var dur = new GlideDuration('3 12:00:00');
    gs.info(dur.getDisplayValue());

Output:

    3 Days 12 Hours

## GlideDuration - getDurationValue() {#ariaid-title10}

Returns the duration value in "d HH:mm:ss" format.
{#r_ScopedGlideDurationGetDurationValue__table_vy2_565_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 13. Parameters]

{#r_ScopedGlideDurationGetDurationValue__table_vy2_565_jq} {#r_ScopedGlideDurationGetDurationValue__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Duration value. Format: d HH:mm:ss where "d" is number of days. |
[Table 14. Returns]

{#r_ScopedGlideDurationGetDurationValue__table_qpt_3f5_jq}  

    var dur = new GlideDuration(60000);
    gs.info(dur.getDurationValue());

Output:

    00:01:00

## GlideDuration - getRoundedDayPart() {#ariaid-title11}

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.
{#r_ScopedGlideDurationGetRoundedDayPart__table_vy2_565_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 15. Parameters]

{#r_ScopedGlideDurationGetRoundedDayPart__table_vy2_565_jq} {#r_ScopedGlideDurationGetRoundedDayPart__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| Number | Day value of the display value rounded. |
[Table 16. Returns]

{#r_ScopedGlideDurationGetRoundedDayPart__table_qpt_3f5_jq}  

    var dur = new GlideDuration('3 14:00:00');
    gs.info(dur.getRoundedDayPart());

Output:

    4

## GlideDuration - getValue() {#ariaid-title12}

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.
{#r_ScopedGlideDurationGetValue__table_vy2_565_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 17. Parameters]

{#r_ScopedGlideDurationGetValue__table_vy2_565_jq} {#r_ScopedGlideDurationGetValue__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Current duration within the GlideDuration object. Format: YYYY-MM-DD HH:mm:ss |
[Table 18. Returns]

{#r_ScopedGlideDurationGetValue__table_qpt_3f5_jq}  

    var dur = new GlideDuration('3 12:00:00');
    gs.info(dur.getValue());

Output:

    1970-01-04 12:00:00

## GlideDuration - setDisplayValue(String asDisplayed) {#ariaid-title13}

Sets the duration display value.
{#r_ScopedGlideDurationSetDisplayValue_String__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| asDisplayed | String | Display duration value to set. Format: d HH:mm:ss where "d" is number of days |
[Table 19. Parameters]

{#r_ScopedGlideDurationSetDisplayValue_String__table_vy2_525_jq} {#r_ScopedGlideDurationSetDisplayValue_String__table_qpt_3f5_jq1__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 20. Returns]

{#r_ScopedGlideDurationSetDisplayValue_String__table_qpt_3f5_jq1}  

    var dur = new GlideDuration(); 
    dur.setDisplayValue('3 08:00:00');
    gs.info(dur.getDisplayValue());

Output:

    3 Days 8 Hours

## GlideDuration - setValue(Object o) {#ariaid-title14}

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.
{#r_ScopedGlideDurationSetValue_Object__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| o | Object | Date and time to use as the endpoint for the calculated duration time. Format: YYYY-MM-DD HH:mm:ss |
[Table 21. Parameters]

{#r_ScopedGlideDurationSetValue_Object__table_vy2_525_jq} {#r_ScopedGlideDurationSetValue_Object__table_qpt_3f5_jq1__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 22. Returns]

{#r_ScopedGlideDurationSetValue_Object__table_qpt_3f5_jq1}  

    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) {#ariaid-title15}

Subtracts the duration of the specified GlideDuration object to the current
GlideDuration object.
{#r_ScopedGlideDurationSubtract_GlideDuration__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| duration | GlideDuration | GlideDuration object that contains the duration value to subtract from the current GlideDuration object. |
[Table 23. Parameters]

{#r_ScopedGlideDurationSubtract_GlideDuration__table_vy2_525_jq} {#r_ScopedGlideDurationSubtract_GlideDuration__table_qpt_3f5_jq1__entry__2}

| Type | Description |
|-|-|
| GlideDuration | New GlideDuration object whose duration contains the result of the subtraction of the duration of the two GlideDuration objects. |
[Table 24. Returns]

{#r_ScopedGlideDurationSubtract_GlideDuration__table_qpt_3f5_jq1}  

    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


