---
sourceDocument: Australia API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/de-DE/api-reference

 Release :

    - australia

ft:locale :

    - de-DE

ft:publication_title :

    - Australia API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideDateTime - Global

# GlideDateTime - Global {#ariaid-title1}

* Freigeben Version: Australia
* 
* Aktualisiert 12. März 2026
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 36 Minuten Lesedauer

The GlideDateTime class provides methods for performing operations on GlideDateTime objects.

Use the GlideDateTime methods to perform date-time operations, such as instantiating a GlideDateTime object, performing date-time calculations, formatting a date-time, or converting between date-time formats.

For guidance on date time input strings with a list of common format conflicts, refer to [Date and time format guidelines](https://servicenow-prod.fluidtopics.net/dzmy~SPwYKtdZjkFXPdUHw#date-and-time-format-guidelines "You can specify a date format with a sequence of specific date and time pattern strings. A pattern string consists of one or more uppercase and lowercase letters from A to Z. Any text within quotation marks is ignored and is instead copied into the date output.").

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

Instantiates a new GlideDateTime object with the current date and time.
{#r_GDT-GlideDateTime__table_qpq_slc_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 1. Parameters]

{#r_GDT-GlideDateTime__table_qpq_slc_nt}  
This example instantiates a GlideDateTime object.

    var gdt = new GlideDateTime();
    gs.info(gdt);

Output:

    2022-08-08 16:51:44

## GlideDateTime - GlideDateTime(String dateTime) {#ariaid-title3}

Instantiates a new GlideDateTime object using the passed-in date and time value.
The system attempts to match the passed-in value with the specified internal system format. If the argument does not match the system format, the system attempts to match it to one of the following formats in this order:

* yyyy-MM-dd HH:mm:ss
* MM/dd/yyyy HH:mm:ss
* MM-dd-yyyy HH:mm:ss
* MM-dd-yyyy HH:mm
* MM-dd-yyyy
* MM/dd/yyyy
* dd-MM-yyyy HH:mm:ss
* dd-MM-yyyy HH.mm.ss
* dd-MM-yyyy HH.mm
* dd-MM-yy HH.mm.ss
* dd/MM/yyyy
* dd-MM-yyyy
* yyyy-MM-dd HH:mm
* yyyy-MM-dd
* dd.MM.yyyy HH:mm:ss
* dd.MM.yyyy HH.mm.ss
* dd.MM.yyyy hh:mm:ss a
* dd.MM.yyyy hh.mm.ss a
* dd.MM.yyyy

{#r_GDT-GlideDateTime_S__ul_xgq_hmz_lnb}  
Hinweis:  
The following format is not supported:

* yyyy-MM-dd'T'HH:mm:ss.SSSZ
{#r_GDT-GlideDateTime_S__ul_udg_d5w_lcc}
{#r_GDT-GlideDateTime_S__table_ufk_jmc_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| dateTime | String | UTC date and time to set in the GlideDateTime object. |
[Tabelle : 2. Parameters]

{#r_GDT-GlideDateTime_S__table_ufk_jmc_nt}  
This example shows how to instantiate a GlideDateTime object using a string.

    var gdt = new GlideDateTime("2023-01-01 12:00:00");
    gs.info(gdt);

Output:

    2023-01-01 12:00:00

## GlideDateTime - GlideDateTime(GlideDateTime gdt) {#ariaid-title4}

Instantiates a new GlideDateTime object set to the time of a specified GlideDateTime object.
{#r_GDT-GlideDateTime_GDT__table_jqw_cnc_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| gdt | GlideDateTime | Object used to set the time of the new object. |
[Tabelle : 3. Parameters]

{#r_GDT-GlideDateTime_GDT__table_jqw_cnc_nt}  
This example shows how to instantiate a GlideDateTime object (gdt1) using a string in the format `yyyy-MM-dd HH:mm:ss`, and a second GlideDateTime object (gdt2) using
gdt1.

    var gdt1 = new GlideDateTime("2025-01-28 12:00:00"); // GlideDateTime(String g)
    var gdt2 = new GlideDateTime(gdt1); // GlideDateTime(GlideDateTime g)
    gs.info(gdt1);
    gs.info(gdt2);

Output:

    2025-01-28 12:00:00
    2025-01-28 12:00:00

## GlideDateTime - add(Number milliseconds) {#ariaid-title5}

Adds a specified number of milliseconds to the GlideDateTime object.
{#r_GDT-add_N__table_x2g_nsl_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| milliseconds | Number | The number of milliseconds to add |
[Tabelle : 4. Parameters]

{#r_GDT-add_N__table_x2g_nsl_nt} {#r_GDT-add_N__table_y2g_nsl_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 5. Returns]

{#r_GDT-add_N__table_y2g_nsl_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gs.print(gdt.getNumericValue());
    gdt.add(10);
    gs.print(gdt.getNumericValue());

Output:

    1314777600000
    1314777600010

### Scoped equivalent {#r_GDT-add_N__section_bqp_jnr_mcb}

To use the add() method in a scoped application, use the corresponding
scoped method: [add()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeAdd_Number "Adds the specified number of milliseconds to the current GlideDateTime object.").

## GlideDateTime - add(GlideTime time) {#ariaid-title6}

Adds a GlideTime object to the current GlideDateTime object.
{#r_GDT-add_GT__table_e4r_xs2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| time | [GlideTime](https://servicenow-prod.fluidtopics.net/BrX~sh9o087pQzX71TsvHA#c_GlideTimeScopedAPI "The GlideTime API provides methods for performing operations on GlideTime objects, such as instantiating GlideTime objects or working with GlideTime fields.") | GlideTime object whose time value to add to the specified GlideDateTime object. |
[Tabelle : 6. Parameters]

{#r_GDT-add_GT__table_e4r_xs2_nt} {#r_GDT-add_GT__table_f4r_xs2_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 7. Returns]

{#r_GDT-add_GT__table_f4r_xs2_nt}  
This example shows how to add 20 seconds to the time set in the gdt GlideDateTime
object.

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    var gtime1 = new GlideTime();
    gtime1.setValue("00:00:20");
    gdt.add(gtime1);
    gs.print(gdt.toString());

Output:

    2011-08-31 08:00:20

### Scoped equivalent {#r_GDT-add_GT__section_prv_gnr_mcb}

To use the add() method in a scoped application, use the corresponding
scoped method: [add()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeAdd_GlideTime_gd "Adds a GlideTime object to the current GlideDateTime object.").

## GlideDateTime - addDays(Number days) {#ariaid-title7}

Adds a specified number of days to the current GlideDateTime object. A negative
parameter subtracts days.
This method isn't available in scoped applications. You can alternatively use addDaysLocalTime() or addDaysUTC() in scoped applications.
{#r_GDT-addDays_N__table_h1q_3t2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| days | Number | The number of days to add. Use a negative number to subtract. |
[Tabelle : 8. Parameters]

{#r_GDT-addDays_N__table_h1q_3t2_nt} {#r_GDT-addDays_N__table_i1q_3t2_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 9. Returns]

{#r_GDT-addDays_N__table_i1q_3t2_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gdt.addDays(-1);
    gs.print(gdt.getDate());

Output:

    2011-08-30

## GlideDateTime - addDaysLocalTime(Number days) {#ariaid-title8}

Adds a specified number of days to the current GlideDateTime object. A negative
parameter subtracts days.
The method determines the local date and time equivalent to the value stored by the
GlideDateTime object, then adds or subtracts days using the local date and time values.
{#r_GDT-addDaysLocalTime_N__table_ll1_xt2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| days | Number | The number of days to add. Use a negative value to subtract. |
[Tabelle : 10. Parameters]

{#r_GDT-addDaysLocalTime_N__table_ll1_xt2_nt} {#r_GDT-addDaysLocalTime_N__table_ml1_xt2_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 11. Returns]

{#r_GDT-addDaysLocalTime_N__table_ml1_xt2_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gdt.addDaysLocalTime(-1);
    gs.print(gdt.getLocalDate());

Output:

    2011-08-30

### Scoped equivalent {#r_GDT-addDaysLocalTime_N__section_hnw_5lr_mcb}

To use the addDaysLocalTime() method in a scoped application, use the
corresponding scoped method: [addDaysLocalTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeAddDaysLocalTime_Number "Adds a specified number of days to the current GlideDateTime object. A negative parameter subtracts days. The method determines the local date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts days using the local date and time values.").

## GlideDateTime - addDaysUTC(Number days) {#ariaid-title9}

Adds a specified number of days to the current GlideDateTime object. A negative
parameter subtracts days.
The method determines the UTC date and time equivalent to the value stored by the
GlideDateTime object, then adds or subtracts days using the UTC date and time values.
{#r_GDT-addDaysUTC_N__table_vyt_k52_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| days | Number | The number of days to add. Use a negative value to subtract. |
[Tabelle : 12. Parameters]

{#r_GDT-addDaysUTC_N__table_vyt_k52_nt} {#r_GDT-addDaysUTC_N__table_wyt_k52_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 13. Returns]

{#r_GDT-addDaysUTC_N__table_wyt_k52_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gdt.addDaysUTC(-1);
    gs.print(gdt.getDate());

Output:

    2011-08-30

### Scoped equivalent {#r_GDT-addDaysUTC_N__section_ljh_ylr_mcb}

To use the addDaysUTC() method in a scoped application, use the
corresponding scoped method: [addDaysUTC()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeAddDaysUTC_Number "Adds a specified number of days to the current GlideDateTime object. A negative parameter subtracts days. The method determines the UTC date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts days using the UTC date and time values.").

## GlideDateTime - addSeconds(Number seconds) {#ariaid-title10}

Adds a specified number of seconds to the GlideDateTime object.
{#r_GDT-addSeconds_N__table_xlx_zsl_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| seconds | Number | The number of seconds to add |
[Tabelle : 14. Parameters]

{#r_GDT-addSeconds_N__table_xlx_zsl_nt} {#r_GDT-addSeconds_N__table_ylx_zsl_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 15. Returns]

{#r_GDT-addSeconds_N__table_ylx_zsl_nt}  

    var gdt = new GlideDateTime("2011-12-07 08:00:00");
    gdt.addSeconds(1000);
    gs.print(gdt.getValue());

Output:

    2011-12-07 08:16:40

### Scoped equivalent {#r_GDT-addSeconds_N__section_mnz_gmr_mcb}

To use the addSeconds() method in a scoped application, use the
corresponding scoped method: [addSeconds()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeAddSeconds_Number "Adds the specified number of seconds to the current GlideDateTime object.").

## GlideDateTime - addWeeks(Number weeks) {#ariaid-title11}

Adds a specified number of weeks to the current GlideDateTime object. A negative
parameter subtracts weeks.
Use addWeeksLocalTime() and addWeeksUTC() instead of
this method.
{#r_GDT-addWeeks_N__table_bpk_v52_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| weeks | Number | The number of weeks to add. Use a negative number to subtract. |
[Tabelle : 16. Parameters]

{#r_GDT-addWeeks_N__table_bpk_v52_nt} {#r_GDT-addWeeks_N__table_cpk_v52_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 17. Returns]

{#r_GDT-addWeeks_N__table_cpk_v52_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gdt.addWeeks(-1);
    gs.print(gdt.getDate());

Output:

    2011-08-24

## GlideDateTime - addWeeksLocalTime(Number weeks) {#ariaid-title12}

Adds a specified number of weeks to the current GlideDateTime object. A negative
parameter subtracts weeks.
The method determines the local date and time equivalent to the value stored by the
GlideDateTime object, then adds or subtracts weeks using the local date and time values.
{#r_GDT-addWeeksLocalTime_N__table_ozv_3v2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| weeks | Number | The number of weeks to add. Use a negative number to subtract. |
[Tabelle : 18. Parameters]

{#r_GDT-addWeeksLocalTime_N__table_ozv_3v2_nt} {#r_GDT-addWeeksLocalTime_N__table_pzv_3v2_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 19. Returns]

{#r_GDT-addWeeksLocalTime_N__table_pzv_3v2_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gdt.addWeeksLocalTime(-1);
    gs.print(gdt.getDate());

Output:

    2011-08-24

### Scoped equivalent {#r_GDT-addWeeksLocalTime_N__section_uq1_wmr_mcb}

To use the addWeeksLocalTime() method in a scoped application, use the
corresponding scoped method: [addWeeksLocalTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeAddWeeksLocalTime_Number "Adds a specified number of weeks to the current GlideDateTime object. A negative parameter subtracts weeks. The method determines the local date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts weeks using the local date and time values.").

## GlideDateTime - addWeeksUTC(Number weeks) {#ariaid-title13}

Adds a specified number of weeks to the current GlideDateTime object. A negative
parameter subtracts weeks.
The method determines the UTC date and time equivalent to the value stored by the
GlideDateTime object, then adds or subtracts weeks using the UTC date and time values.
{#r_GDT-addWeeksUTC_N__table_rdr_5v2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| weeks | Number | The number of weeks to add. Use a negative number to subtract. |
[Tabelle : 20. Parameters]

{#r_GDT-addWeeksUTC_N__table_rdr_5v2_nt} {#r_GDT-addWeeksUTC_N__table_sdr_5v2_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 21. Returns]

{#r_GDT-addWeeksUTC_N__table_sdr_5v2_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gdt.addWeeksUTC(-1);
    gs.print(gdt.getDate());

Output:

    2011-08-24

### Scoped equivalent {#r_GDT-addWeeksUTC_N__section_pnm_ymr_mcb}

To use the addWeeksUTC() method in a scoped application, use the
corresponding scoped method: [addWeeksUTC()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeAddWeeksUTC_Number "Adds a specified number of weeks to the current GlideDateTime object. A negative parameter subtracts weeks. The method determines the UTC date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts weeks using the UTC date and time values.").

## GlideDateTime - addMonths(Number months) {#ariaid-title14}

Adds a specified number of months to the current GlideDateTime object. A negative
parameter subtracts months.
Use addMonthsLocalTime() or addMonthsUTC() instead of
this method.
{#r_GDT-addMonths_N__table_tgm_bkk_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| months | Number | The number of months to add. Use a negative number to subtract. |
[Tabelle : 22. Parameters]

{#r_GDT-addMonths_N__table_tgm_bkk_nt} {#r_GDT-addMonths_N__table_ugm_bkk_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 23. Returns]

{#r_GDT-addMonths_N__table_ugm_bkk_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gdt.addMonths(2);
    gs.print(gdt.getDate());

Output:

    2011-10-31

## GlideDateTime - addMonthsLocalTime(Number months) {#ariaid-title15}

Adds a specified number of months to the current GlideDateTime object. A negative
parameter subtracts months.
The method determines the local date and time equivalent to the value stored by the
GlideDateTime object, then adds or subtracts months using the local date and time
values.
{#r_GDT-addMonthsLocalTime_N__table_fmn_pkk_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| months | Number | The number of months to add. Use a negative value to subtract. |
[Tabelle : 24. Parameters]

{#r_GDT-addMonthsLocalTime_N__table_fmn_pkk_nt} {#r_GDT-addMonthsLocalTime_N__table_gmn_pkk_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 25. Returns]

{#r_GDT-addMonthsLocalTime_N__table_gmn_pkk_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gdt.addMonthsLocalTime(2);
    gs.print(gdt.getDate());

Output:

    2011-10-31

### Scoped equivalent {#r_GDT-addMonthsLocalTime_N__section_xvc_bmr_mcb}

To use the addMonthsLocalTime() method in a scoped application, use the
corresponding scoped method: [addMonthsLocalTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeAddMonthsLocalTime_Number "Adds a specified number of months to the current GlideDateTime object. A negative parameter subtracts months. The method determines the local date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts months using the local date and time values.").

## GlideDateTime - addMonthsUTC(Number months) {#ariaid-title16}

Adds a specified number of months to the current GlideDateTime object. A negative
parameter subtracts months.
The method determines the UTC date and time equivalent to the value stored by the
GlideDateTime object, then adds or subtracts months using the UTC date and time values.
{#r_GDT-addMonthsUTC_N__table_lqp_1lk_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| months | Number | The number of months to add. Use a negative number to subtract. |
[Tabelle : 26. Parameters]

{#r_GDT-addMonthsUTC_N__table_lqp_1lk_nt} {#r_GDT-addMonthsUTC_N__table_mqp_1lk_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 27. Returns]

{#r_GDT-addMonthsUTC_N__table_mqp_1lk_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gdt.addMonthsUTC(2);
    gs.print(gdt.getDate());

Output:

    2011-10-31

### Scoped equivalent {#r_GDT-addMonthsUTC_N__section_gxn_2mr_mcb}

To use the addMonthsUTC() method in a scoped application, use the
corresponding scoped method: [addMonthsUTC()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeAddMonthsUTC_Number "Adds a specified number of months to the current GlideDateTime object. A negative parameter subtracts months. The method determines the UTC date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts months using the UTC date and time values.").

## GlideDateTime - addYears(Number years) {#ariaid-title17}

Adds a specified number of years to the current GlideDateTime object. A negative
parameter subtracts years.
Use addYearsLocalTime() or addYearsUTC() instead of
this method.
{#r_GDT-addYears_N__table_fpz_mlk_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| years | Number | The number of years to add. Use a negative value to subtract. |
[Tabelle : 28. Parameters]

{#r_GDT-addYears_N__table_fpz_mlk_nt} {#r_GDT-addYears_N__table_gpz_mlk_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 29. Returns]

{#r_GDT-addYears_N__table_gpz_mlk_nt}  

    var gdt = new GlideDateTime("2010-08-31 08:00:00");
    gdt.addYears(1);
    gs.print(gdt.getDate());

Output:

    2011-08-31

## GlideDateTime - addYearsLocalTime(Number years) {#ariaid-title18}

Adds a specified number of years to the current GlideDateTime object. A negative
parameter subtracts years.
The method determines the local date and time equivalent to the value stored by the
GlideDateTime object, then adds or subtracts years using the local date and time values.
{#r_GDT-addYearsLocalTime_N__table_llj_ryk_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| years | Number | The number of years to add. To subtract use a negative value. |
[Tabelle : 30. Parameters]

{#r_GDT-addYearsLocalTime_N__table_llj_ryk_nt} {#r_GDT-addYearsLocalTime_N__table_mlj_ryk_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 31. Returns]

{#r_GDT-addYearsLocalTime_N__table_mlj_ryk_nt}  

    var gdt = new GlideDateTime("2010-08-31 08:00:00");
    gdt.addYearsLocalTime(1);
    gs.print(gdt.getDate());

Output:

    2011-08-31

### Scoped equivalent {#r_GDT-addYearsLocalTime_N__section_yhl_bnr_mcb}

To use the AddYearsLocalTime() method in a scoped application, use the
corresponding scoped method: [AddYearsLocalTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeAddYearsLocalTime_Number "Adds a specified number of years to the current GlideDateTime object. A negative parameter subtracts years. The method determines the local date and time equivalent to the value stored by the GlideDateTime object, then adds or subtracts years using the local date and time values.").

## GlideDateTime - addYearsUTC(Number years) {#ariaid-title19}

Adds a specified number of years to the current GlideDateTime object. A negative
parameter subtracts years.
The date and time value stored by GlideDateTime object is interpreted as being in the UTC
time zone.
{#r_GDT-addYearsUTC_N__table_njl_czk_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| years | Number | The number of years to add. Use a negative value to subtract. |
[Tabelle : 32. Parameters]

{#r_GDT-addYearsUTC_N__table_njl_czk_nt} {#r_GDT-addYearsUTC_N__table_ojl_czk_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 33. Returns]

{#r_GDT-addYearsUTC_N__table_ojl_czk_nt}  

    var gdt = new GlideDateTime("2010-08-31 08:00:00");
    gdt.addYearsUTC(1);
    gs.print(gdt.getDate());

Output:

    2011-08-31

### Scoped equivalent {#r_GDT-addYearsUTC_N__section_yj1_2nr_mcb}

To use the addYearsUTC() method in a scoped application, use the
corresponding scoped method: [addYearsUTC()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeAddYearsUTC_Number "Adds a specified number of years to the current GlideDateTime object. A negative parameter subtracts years. The date and time value stored by GlideDateTime object is interpreted as being in the UTC time zone.").

## GlideDateTime - compareTo(Object dateTime) {#ariaid-title20}

Compares two date and time objects to determine whether one occurs before the other or
if they are equivalent.
{#r_GDT-compareTo_O__table_sc3_rbd_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| dateTime | Object | Date time in a GlideDateTime object |
[Tabelle : 34. Parameters]

{#r_GDT-compareTo_O__table_sc3_rbd_nt} {#r_GDT-compareTo_O__table_tc3_rbd_nt__entry__2}

| Type | Description |
|-|-|
| Number | * 0 = Dates are equal * 1 = The object's date is after the date specified in the parameter * -1 = The object's date is before the date specified in the parameter {#r_GDT-compareTo_O__ul_tb3_mjg_sz} |
[Tabelle : 35. Returns]

{#r_GDT-compareTo_O__table_tc3_rbd_nt}  

    var initDate = new GlideDateTime("2011-08-01 12:00:00");
    var compDate1 = new GlideDateTime("2011-08-01 12:00:00");
    var compDate2 = new GlideDateTime("2011-07-31 12:00:00");
    var compDate3 = new GlideDateTime("2011-08-04 16:00:00");
     
    gs.info(initDate.compareTo(compDate1)); // Equals (0)
    gs.info(initDate.compareTo(compDate2)); // initDate is after compDate2 (1)
    gs.info(initDate.compareTo(compDate3)); // initDate is before compDate3 (-1)

Output:

    0
    1
    -1

### Scoped equivalent {#r_GDT-compareTo_O__section_opf_mnr_mcb}

To use the compareTo() method in a scoped application, use the
corresponding scoped method: [compareTo()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeCompareTo_Object_o "Compares two date and time objects to determine whether they are equivalent or one occurs before or after the other.").

## GlideDateTime - equals(Object GDT) {#ariaid-title21}

Compares an object with an existing value for equality.
{#r_GDT-equals_O__table_njf_vvl_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| GDT | Object | The object to compare. Can be a GlideDateTIme object or a valid date time string. |
[Tabelle : 36. Parameters]

{#r_GDT-equals_O__table_njf_vvl_nt} {#r_GDT-equals_O__table_ojf_vvl_nt__entry__2}

| Type | Description |
|-|-|
| Boolean | True if they are equal, false otherwise. |
[Tabelle : 37. Returns]

{#r_GDT-equals_O__table_ojf_vvl_nt}  

    var gdt = new GlideDateTime("2011-08-31 00:00:00");
    gs.print(gdt.equals("2011-09-30 00:12:01"));

Output:

     false

### Scoped equivalent {#r_GDT-equals_O__section_i3p_4nr_mcb}

To use the equals() method in a scoped application, use the
corresponding scoped method: [equals()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeEquals_Object "Compares a datetime with an existing value for equality.").

## GlideDateTime - getDate() {#ariaid-title22}

Returns the date stored by the GlideDateTime object. Expressed in the format yyyy-MM-dd
and in the system time zone, UTC by default.
{#r_GDT-getDate__table_mjv_xq2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 38. Parameters]

{#r_GDT-getDate__table_mjv_xq2_nt} {#r_GDT-getDate__table_njv_xq2_nt__entry__2}

| Type | Description |
|-|-|
| String | Date in the system time zone. Format: yyyy-MM-dd, and in the system time zone, UTC by default. |
[Tabelle : 39. Returns]

{#r_GDT-getDate__table_njv_xq2_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gs.info(gdt.getDate());

Output:

    2011-08-31

### Scoped equivalent {#r_GDT-getDate__section_xpq_tnr_mcb}

To use the getDate() method in a scoped application, use the
corresponding scoped method: [getDate()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetDate "Returns the date stored by the GlideDateTime object. Expressed in the standard format, yyyy-MM-dd, and in the system time zone, GMT by default.").

## GlideDateTime - getDayOfMonth() {#ariaid-title23}

Gets the current day of the month in the UTC time zone.
Deprecated. Use getDayOfMonthLocalTime() and getDayOfMonthUTC() instead of this method.
{#r_GDT-getDayOfMonth__table_orj_hg2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 40. Parameters]

{#r_GDT-getDayOfMonth__table_orj_hg2_nt} {#r_GDT-getDayOfMonth__table_prj_hg2_nt__entry__2}

| Type | Description |
|-|-|
| Number | The day of the month in the UTC time zone, from 1 to 31. |
[Tabelle : 41. Returns]

{#r_GDT-getDayOfMonth__table_prj_hg2_nt}  

    var gdt = new GlideDateTime("2011-12-02 12:00:00");
    gs.print(gdt.getDayOfMonth());

Output:

    2

## GlideDateTime - getDayOfMonthLocalTime() {#ariaid-title24}

Gets the day of the month stored by the GlideDateTime object, expressed in the current
user's time zone.
{#r_GDT-getDayOfMonthLocalTime__table_e4r_wg2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 42. Parameters]

{#r_GDT-getDayOfMonthLocalTime__table_e4r_wg2_nt} {#r_GDT-getDayOfMonthLocalTime__table_f4r_wg2_nt__entry__2}

| Type | Description |
|-|-|
| Number | The day of the month in the user's time zone, from 1 to 31. |
[Tabelle : 43. Returns]

{#r_GDT-getDayOfMonthLocalTime__table_f4r_wg2_nt}  

    var gdt = new GlideDateTime("2011-12-02 12:00:00");
    gs.print(gdt.getDayOfMonthLocalTime());

Output:

    2

### Scoped equivalent {#r_GDT-getDayOfMonthLocalTime__section_ap5_d4r_mcb}

To use the getDayOfMonthLocalTime() method in a scoped application, use
the corresponding scoped method: [getDayOfMonthLocalTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetDayOfMonthLocalTime "Gets the day of the month stored by the GlideDateTime object, expressed in the current user's time zone.").

## GlideDateTime - getDayOfMonthUTC() {#ariaid-title25}

Gets the day of the month stored by the GlideDateTime object, expressed in the UTC time
zone.
{#r_GDT-getDayOfMonthUTC__table_hhb_nh2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 44. Parameters]

{#r_GDT-getDayOfMonthUTC__table_hhb_nh2_nt} {#r_GDT-getDayOfMonthUTC__table_ihb_nh2_nt__entry__2}

| Type | Description |
|-|-|
| Number | The day of the month in the UTC time zone, from 1 to 31. |
[Tabelle : 45. Returns]

{#r_GDT-getDayOfMonthUTC__table_ihb_nh2_nt}  

    var gdt = new GlideDateTime("2011-12-02 12:00:00");
    gs.print(gdt.getDayOfMonthUTC());

Output:

    2

### Scoped equivalent {#r_GDT-getDayOfMonthUTC__section_rvd_34r_mcb}

To use the getDayOfMonthUTC() method in a scoped application, use the
corresponding scoped method: [getDayOfMonthUTC()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetDayOfMonthUTC "Gets the day of the month stored by the GlideDateTime object, expressed in the UTC time zone.").

## GlideDateTime - getDayOfWeek() {#ariaid-title26}

Retrieves the day of the week stored by the GlideDateTime object, expressed in the
user's time zone.
Use getDayOfWeekLocalTime() and getDayOfWeekUTC()
instead of this method.
{#r_GDT-getDayOfWeek__table_yvw_zc2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 46. Parameters]

{#r_GDT-getDayOfWeek__table_yvw_zc2_nt} {#r_GDT-getDayOfWeek__table_zvw_zc2_nt__entry__2}

| Type | Description |
|-|-|
| Number | The day of the week value - Monday = 1, ... Sunday = 7. |
[Tabelle : 47. Returns]

{#r_GDT-getDayOfWeek__table_zvw_zc2_nt}  

    var gdt = new GlideDateTime("2011-12-01 12:00:00");
    gs.print(gdt.getDayOfWeek());

Output:

    4

## GlideDateTime - getDayOfWeekLocalTime() {#ariaid-title27}

Gets the day of the week stored by the GlideDateTime object, expressed in the user's
time zone.
{#r_GDT-getDayOfWeekLocalTime__table_xmt_qd2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 48. Parameters]

{#r_GDT-getDayOfWeekLocalTime__table_xmt_qd2_nt} {#r_GDT-getDayOfWeekLocalTime__table_ymt_qd2_nt__entry__2}

| Type | Description |
|-|-|
| Number | The day of the week value - Monday = 1, ... Sunday = 7 |
[Tabelle : 49. Returns]

{#r_GDT-getDayOfWeekLocalTime__table_ymt_qd2_nt}  

    var gdt = new GlideDateTime("2011-12-01 12:00:00");
    gs.print(gdt.getDayOfWeekLocalTime());

Output:

    4

### Scoped equivalent {#r_GDT-getDayOfWeekLocalTime__section_lmp_k4r_mcb}

To use the getDayOfWeekLocalTime() method in a scoped application, use
the corresponding scoped method: [getDayOfWeekLocalTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetDayOfWeekLocalTime "Gets the day of the week stored by the GlideDateTime object, expressed in the user's time zone.").

## GlideDateTime - getDayOfWeekUTC() {#ariaid-title28}

Gets the day of the week stored by the GlideDateTime object, expressed in the UTC time
zone.
{#r_GDT-getDayOfWeekUTC__table_bwl_b22_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 50. Parameters]

{#r_GDT-getDayOfWeekUTC__table_bwl_b22_nt} {#r_GDT-getDayOfWeekUTC__table_cwl_b22_nt__entry__2}

| Type | Description |
|-|-|
| Number | The day of the week value - Monday = 1, ... Sunday = 7 |
[Tabelle : 51. Returns]

{#r_GDT-getDayOfWeekUTC__table_cwl_b22_nt}  

    var gdt = new GlideDateTime("2011-12-01 12:00:00");
    gs.print(gdt.getDayOfWeekUTC());

Output:

    4

### Scoped equivalent {#r_GDT-getDayOfWeekUTC__section_ddt_n4r_mcb}

To use the getDayOfWeekUTC() method in a scoped application, use the
corresponding scoped method: [getDayOfWeekUTC()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetDayOfWeekUTC "Returns the day of the week stored by the GlideDateTime object, expressed in the UTC time zone.").

## GlideDateTime - getDaysInMonth() {#ariaid-title29}

Gets the number of days in the month stored by the GlideDateTime object, expressed in
the Java Virtual Machine time zone.
Use getDaysInMonthLocalTime() and getDaysInMonthUTC()
instead of this method.
{#r_GDT-getDaysInMonth__table_s3d_yj2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 52. Parameters]

{#r_GDT-getDaysInMonth__table_s3d_yj2_nt} {#r_GDT-getDaysInMonth__table_t3d_yj2_nt__entry__2}

| Type | Description |
|-|-|
| Number | The number of days in the current month in the Java Virtual Machine time zone. |
[Tabelle : 53. Returns]

{#r_GDT-getDaysInMonth__table_t3d_yj2_nt}  

    var gdt = new GlideDateTime(); //December
    gs.print(gdt.getDaysInMonth());

Output:

    31

## GlideDateTime - getDaysInMonthLocalTime() {#ariaid-title30}

Gets the number of days in the month stored by the GlideDateTime object, expressed in
the current user's time zone.
{#r_GDT-getDaysInMonthLocalTime__table_sjf_lk2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 54. Parameters]

{#r_GDT-getDaysInMonthLocalTime__table_sjf_lk2_nt} {#r_GDT-getDaysInMonthLocalTime__table_tjf_lk2_nt__entry__2}

| Type | Description |
|-|-|
| Number | The number of days in the current month in the user's time zone. |
[Tabelle : 55. Returns]

{#r_GDT-getDaysInMonthLocalTime__table_tjf_lk2_nt}  

    var gdt = new GlideDateTime(); //December
    gs.print(gdt.getDaysInMonthLocalTime());

Output:

    31

### Scoped equivalent {#r_GDT-getDaysInMonthLocalTime__section_z35_q4r_mcb}

To use the getDaysInMonthLocalTime() method in a scoped application, use
the corresponding scoped method: [getDaysInMonthLocalTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetDaysInMonthLocalTime "Gets the number of days in the month stored by the GlideDateTime object, expressed in the current user's time zone.").

## GlideDateTime - getDaysInMonthUTC() {#ariaid-title31}

Gets the number of days in the month stored by the GlideDateTime object, expressed in
the UTC time zone.
{#r_GDT-getDaysInMonthUTC__table_hwd_ll2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 56. Parameters]

{#r_GDT-getDaysInMonthUTC__table_hwd_ll2_nt} {#r_GDT-getDaysInMonthUTC__table_iwd_ll2_nt__entry__2}

| Type | Description |
|-|-|
| Number | The number of days in the month stored by the GlideDateTime object, expressed in the UTC time zone. |
[Tabelle : 57. Returns]

{#r_GDT-getDaysInMonthUTC__table_iwd_ll2_nt}  

    var gdt = new GlideDateTime(); //December
    gs.print(gdt.getDaysInMonthUTC());

Output:

    31

### Scoped equivalent {#r_GDT-getDaysInMonthUTC__section_l4t_54r_mcb}

To use the getDaysInMonthUTC() method in a scoped application, use the
corresponding scoped method: [getDaysInMonthUTC()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetDaysInMonthUTC "Gets the number of days in the month stored by the GlideDateTime object, expressed in the UTC time zone.").

## GlideDateTime - getDisplayValue() {#ariaid-title32}

Gets the date and time value in the current user's display format and time
zone.
Hinweis:  
Referring to the GlideDateTime object directly returns the date and time value in the GMT time zone.
{#r_GDT-getDisplayValue__table_lyf_h1d_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 58. Parameters]

{#r_GDT-getDisplayValue__table_lyf_h1d_nt} {#r_GDT-getDisplayValue__table_myf_h1d_nt__entry__2}

| Type | Description |
|-|-|
| Object | Date and time in the user's format and time zone. Keep in mind when designing business rules or script includes that this method may return values in different formats for different users. |
[Tabelle : 59. Returns]

{#r_GDT-getDisplayValue__table_myf_h1d_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gs.info(gdt.getDisplayValue());

Output:

    2011-08-31 01:00:00

### Scoped equivalent {#r_GDT-getDisplayValue__section_u2f_x4r_mcb}

To use the getDisplayValue() method in a scoped application, use the
corresponding scoped method: [getDisplayValue()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetDisplayValue "Gets the date and time value in the current user's display format and time zone.").

## GlideDateTime - getDisplayValueInternal() {#ariaid-title33}

Returns the display value in the internal format, yyyy-MM-dd HH:mm:ss. This method is
useful for date/time fields, but not for date fields.
{#r_GDT-getDisplayValueInternal__table_ocw_t1d_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 60. Parameters]

{#r_GDT-getDisplayValueInternal__table_ocw_t1d_nt} {#r_GDT-getDisplayValueInternal__table_pcw_t1d_nt__entry__2}

| Type | Description |
|-|-|
| Object | The date and time values for the GlideDateTime object. Format: yyyy-MM-dd HH:mm:ss in the caller's time zone. |
[Tabelle : 61. Returns]

{#r_GDT-getDisplayValueInternal__table_pcw_t1d_nt}  

    // The passed in date and time is converted to the caller's time zone.
    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gs.info(gdt.getDisplayValueInternal());

Output:

    2011-08-31 01:00:00

### Scoped equivalent {#r_GDT-getDisplayValueInternal__section_jng_z4r_mcb}

To use the getDisplayValueInternal() method in a scoped application, use
the corresponding scoped method: [getDisplayValueInternal()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetDisplayValueInternal "Gets the display value in the internal format (yyyy-MM-dd HH:mm:ss).").

## GlideDateTime - getDisplayValueLang(String style) {#ariaid-title34}

Returns a date and time value in the current user's locale according to the specified
date style.
{#r_GDT-getDisplayValueLang_S__id_zqf_hvw_dwb__entry__3}

| Name | Type | Description |
|-|-|-|
| style | String | Specifies the date and time format. Valid values: * full: returns the date in the format of \<weekday, month, day, and year\> according to the user's locale (for example, Monday, October 24, 2022). * long: returns the date in the format of \<month, day, and year\> according to the user's locale (for example, October 24, 2022). * medium: similar to long but returns the date with an abbreviated month (for example, Oct 24, 2022). * short: returns the date in the format of MM/DD/YY or DD/MM/YY according to the user's locale (for example, 10/24/2022 or 24/10/2022). If any other value is passed the API will default to use <var class="keyword varname">medium</var>. Accepted values are not case sensitive. |
[Tabelle : 62. Parameters]

{#r_GDT-getDisplayValueLang_S__id_zqf_hvw_dwb} {#r_GDT-getDisplayValueLang_S__id_pp1_3vw_dwb__entry__2}

| Type | Description |
|-|-|
| String | A string representation of the date in the style specified and in the appropriate format for the locale of the current user. |
[Tabelle : 63. Returns]

{#r_GDT-getDisplayValueLang_S__id_pp1_3vw_dwb}  
The following example returns the date and time of the user's locale in all date
styles.

    var gdt = new GlideDateTime(); // This will fetch the current date


    gs.info('date: ' + gdt.getDisplayValue());

    gs.info('date: ' + gdt.getDisplayValueLang("full"));
    gs.info('date: ' + gdt.getDisplayValueLang("long"));
    gs.info('date: ' + gdt.getDisplayValueLang("medium"));
    gs.info('date: ' + gdt.getDisplayValueLang("short"));

Output:

    date: 2023-01-18 06:49:02
    date: Wednesday, January 18, 2023 06:49:02
    date: January 18, 2023 06:49:02
    date: Jan 18, 2023 06:49:02
    date: 1/18/23 06:49:02

## GlideDateTime - getDisplayValueLang(String style, String language) {#ariaid-title35}

Returns a date and time value in the current user's locale according to a specified
language and date style.
{#r_GDT-getDisplayValueLang_S_S__id_dfb_4vw_dwb__entry__3}

| Name | Type | Description |
|-|-|-|
| style | String | Specifies the date and time format. Valid values: * full: returns the date in the format of \<weekday, month, day, and year\> according to the user's locale (for example, Monday, October 24, 2022). * long: returns the date in the format of \<month, day, and year\> according to the user's locale (for example, October 24, 2022). * medium: similar to long but returns the date with an abbreviated month (for example, Oct 24, 2022). * short: returns the date in the format of MM/DD/YY or DD/MM/YY according to the user's locale (for example, 10/24/2022 or 24/10/2022). If any other value is passed the API will default to use <var class="keyword varname">medium</var>. Accepted values are not case sensitive. |
| language | String | Returns the date according to a specified language value. Accepts language tags that conform with the BCP-47 standard. For example, `fr` for French or `en-UK` for British English. For a full list of accepted values, see [BCP 47 Language Code List](https://appmakers.dev/bcp-47-language-codes-list/). |
[Tabelle : 64. Parameters]

{#r_GDT-getDisplayValueLang_S_S__id_dfb_4vw_dwb} {#r_GDT-getDisplayValueLang_S_S__id_v5l_4vw_dwb__entry__2}

| Type | Description |
|-|-|
| String | A string representation of the date in the style specified and in the appropriate format for the locale of the current user. |
[Tabelle : 65. Returns]

{#r_GDT-getDisplayValueLang_S_S__id_v5l_4vw_dwb}  
The following example returns the date and time of the user's locale in all language and
date styles.

    var gdt = new GlideDateTime(); // This will fetch the current date


    gs.info('date: ' + gdt.getDisplayValue());

    gs.info('date: ' + gdt.getDisplayValueLang("full", "fr"));
    gs.info('date: ' + gdt.getDisplayValueLang("long", "en-GB"));
    gs.info('date: ' + gdt.getDisplayValueLang("medium", "de"));
    gs.info('date: ' + gdt.getDisplayValueLang("short", "es-MX"));```

Output:

    date: 2023-01-18 06:49:02
    mercredi 18 janvier 2023 06:49:02
    18 January 2023 06:49:02
    18.01.2023 06:49:02
    18/01/23 06:49:02

## GlideDateTime - getDSTOffset() {#ariaid-title36}

Gets the amount of time that daylight saving time is offset.
{#r_GDT-getDSTOffset__table_iyb_vvc_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 66. Parameters]

{#r_GDT-getDSTOffset__table_iyb_vvc_nt} {#r_GDT-getDSTOffset__table_jyb_vvc_nt__entry__2}

| Type | Description |
|-|-|
| Number | Amount of time, in milliseconds, that daylight saving is offset. Returns 0 if there is no offset or if the time is not during daylight saving time. |
[Tabelle : 67. Returns]

{#r_GDT-getDSTOffset__table_jyb_vvc_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gs.print(gdt.getDSTOffset());

Output:

    3600000

### Scoped equivalent {#r_GDT-getDSTOffset__section_myc_rnr_mcb}

To use the getDSTOffset() method in a scoped application, use the
corresponding scoped method: [getDSTOffset()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetDSTOffset "Gets the amount of time that daylight saving time is offset.").

## GlideDateTime - getErrorMsg() {#ariaid-title37}

Gets the current error message.
{#r_GDT-getErrorMsg__table_dks_dsl_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 68. Parameters]

{#r_GDT-getErrorMsg__table_dks_dsl_nt} {#r_GDT-getErrorMsg__table_eks_dsl_nt__entry__2}

| Type | Description |
|-|-|
| Object | The error message |
[Tabelle : 69. Returns]

{#r_GDT-getErrorMsg__table_eks_dsl_nt}  

    var gdt = new GlideDateTime("2011-aa-31 aa:00:00"); //bad
    gs.print(gdt.isValid()); //false
    gs.print(gdt.getErrorMsg()); //reason

Output:

    false
    Could not parse DateTime: 2011-aa-31 aa:00:00

### Scoped equivalent {#r_GDT-getErrorMsg__section_hmx_hpr_mcb}

To use the getErrorMsg() method in a scoped application, use the
corresponding scoped method: [getErrorMsg()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetErrorMsg "Gets the current error message.").

## GlideDateTime - getInternalFormattedLocalTime() {#ariaid-title38}

Returns the object's time in the local time zone and in the internal
format.
{#r_GDT-getInternalFormatedLocalTime__table_izw_h5c_kw__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 70. Parameters]

{#r_GDT-getInternalFormatedLocalTime__table_izw_h5c_kw} {#r_GDT-getInternalFormatedLocalTime__table_jzw_h5c_kw__entry__2}

| Type | Description |
|-|-|
| Object | The object's time in the local time zone and the internal format. |
[Tabelle : 71. Returns]

{#r_GDT-getInternalFormatedLocalTime__table_jzw_h5c_kw}  
This example displays the time in the system time format of the user's timezone.

    var gdt = new GlideDateTime('2022-10-08 01:00:00');
    gs.info(gdt.getDisplayValue());
    gs.info(gdt.getInternalFormattedLocalTime());

Output:

    2022-10-07 06:00:00 PM
    18:00:00

### Scoped equivalent {#r_GDT-getInternalFormatedLocalTime__section_xvx_hc2_dbb}

To use the getInternalFormattedLocalTime() method in a scoped
application, use the corresponding scoped method: [getInternalFormattedLocalTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_SGDT-getInternalFormattedLocalTime "Returns the object's time in the local time zone and in the internal format.").

## GlideDateTime - getInternalMidnight(Number dayOfTheWeek) {#ariaid-title39}

Returns a date and time object set to midnight of a specified day using
UTC.
{#r_GDT-getInternalMidnight_N__table_llc_mp2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| dayOfTheWeek | Number | The day of the week for which to return the date/time object. |
[Tabelle : 72. Parameters]

{#r_GDT-getInternalMidnight_N__table_llc_mp2_nt} {#r_GDT-getInternalMidnight_N__table_mlc_mp2_nt__entry__2}

| Type | Description |
|-|-|
| GlideDateTime | A GlideDateTime object set to midnight. |
[Tabelle : 73. Returns]

{#r_GDT-getInternalMidnight_N__table_mlc_mp2_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gs.print(gdt.getInternalMidnight(2));

Output:

    2011-08-30 00:00:01

## GlideDateTime - getLocalDate() {#ariaid-title40}

Gets the date stored by the GlideDateTime object, expressed in the standard format,
yyyy-MM-dd, and the current user's time zone.
{#r_GDT-getLocalDate__table_ays_hr2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 74. Parameters]

{#r_GDT-getLocalDate__table_ays_hr2_nt} {#r_GDT-getLocalDate__table_bys_hr2_nt__entry__2}

| Type | Description |
|-|-|
| GlideDate | The date in the user's time zone. |
[Tabelle : 75. Returns]

{#r_GDT-getLocalDate__table_bys_hr2_nt}  
This example displays the time in the user's time format in the user's timezone.

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gs.print(gdt.getLocalDate());

Output:

    2011-08-31

### Scoped equivalent {#r_GDT-getLocalDate__section_pg3_lpr_mcb}

To use the getLocalDate() method in a scoped application, use the
corresponding scoped method: [getLocalDate()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetLocalDate "Gets the date stored by the GlideDateTime object, expressed in the standard format, yyyy-MM-dd, and the current user's time zone.").

## GlideDateTime - getLocalTime() {#ariaid-title41}

Gets the time in the user's time zone.
{#r_GDT-getLocalTime__table_t11_4q2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 76. Parameters]

{#r_GDT-getLocalTime__table_t11_4q2_nt} {#r_GDT-getLocalTime__table_u11_4q2_nt__entry__2}

| Type | Description |
|-|-|
| GlideTime | The time in the user's time zone. |
[Tabelle : 77. Returns]

{#r_GDT-getLocalTime__table_u11_4q2_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gs.print(gdt.getLocalTime());

Output:

    1970-01-01 01:00:00

### Scoped equivalent {#r_GDT-getLocalTime__section_kqj_4pr_mcb}

To use the getLocalTime() method in a scoped application, use the
corresponding scoped method: [getLocalTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetLocalTime "Returns a GlideTime object that represents the time portion of the GlideDateTime object in the user's time zone.").

## GlideDateTime - getMonth() {#ariaid-title42}

Retrieves the month stored by the GlideDateTime object, expressed in Java Virtual
Machine time zone.
Use getMonthLocalTime() and getMonthUTC() instead of
this method.
{#r_GDT-getMonth__table_pyx_tl2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 78. Parameters]

{#r_GDT-getMonth__table_pyx_tl2_nt} {#r_GDT-getMonth__table_qyx_tl2_nt__entry__2}

| Type | Description |
|-|-|
| Number | The numerical value of the month, Jan=1, Dec=12. |
[Tabelle : 79. Returns]

{#r_GDT-getMonth__table_qyx_tl2_nt}  

    var gdt = new GlideDateTime(); //December
    gs.print(gdt.getMonth());

Output:

    12

## GlideDateTime - getMonthLocalTime() {#ariaid-title43}

Gets the month stored by the GlideDateTime object, expressed in the current user's time
zone.
{#r_GDT-getMonthLocalTime__table_lcb_gm2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 80. Parameters]

{#r_GDT-getMonthLocalTime__table_lcb_gm2_nt} {#r_GDT-getMonthLocalTime__table_mcb_gm2_nt__entry__2}

| Type | Description |
|-|-|
| Number | The numerical value of the month, Jan=1, Dec=12. |
[Tabelle : 81. Returns]

{#r_GDT-getMonthLocalTime__table_mcb_gm2_nt}  

    var gdt = new GlideDateTime(); //December
    gs.print(gdt.getMonthLocalTime());

Output:

    12

### Scoped equivalent {#r_GDT-getMonthLocalTime__section_mts_pvr_mcb}

To use the getMonthLocalTime() method in a scoped application, use the
corresponding scoped method: [getMonthLocalTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetMonthLocalTime "Gets the month stored by the GlideDateTime object, expressed in the current user's time zone.").

## GlideDateTime - getMonthUTC() {#ariaid-title44}

Gets the month stored by the GlideDateTime object, expressed in the UTC time
zone.
{#r_GDT-getMonthUTC__table_bsp_5m2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 82. Parameters]

{#r_GDT-getMonthUTC__table_bsp_5m2_nt} {#r_GDT-getMonthUTC__table_csp_5m2_nt__entry__2}

| Type | Description |
|-|-|
| Number | The numerical value of the month, Jan=1, Dec=12. |
[Tabelle : 83. Returns]

{#r_GDT-getMonthUTC__table_csp_5m2_nt}  

    var gdt = new GlideDateTime(); //December
    gs.print(gdt.getMonthUTC());

Output:

    12

### Scoped equivalent {#r_GDT-getMonthUTC__section_dvn_svr_mcb}

To use the getMonthUTC() method in a scoped application, use the
corresponding scoped method: [getMonthUTC()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetMonthUTC "Gets the month stored by the GlideDateTime object, expressed in the UTC time zone.").

## GlideDateTime - getNumericValue() {#ariaid-title45}

Gets the number of milliseconds since January 1, 1970, 00:00:00 GMT.
{#r_GDT-getNumericValue__table_vzg_g42_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 84. Parameters]

{#r_GDT-getNumericValue__table_vzg_g42_nt} {#r_GDT-getNumericValue__table_wzg_g42_nt__entry__2}

| Type | Description |
|-|-|
| Number | The number of milliseconds since January 1, 1970, 00:00:00 GMT. |
[Tabelle : 85. Returns]

{#r_GDT-getNumericValue__table_wzg_g42_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gs.print(gdt.getNumericValue());

Output:

    1314777600000

## GlideDateTime - getSpanTime(Number dayOfWeek) {#ariaid-title46}

Retrieves the amount of time elapsed since the midnight of a specified day to the
current time.
{#r_GDT-getSpanTime_N__table_bqw_lf2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| dayOfWeek | Number | Day of week value from 1 to 7. 1 = Monday, 7=Sunday. |
[Tabelle : 86. Parameters]

{#r_GDT-getSpanTime_N__table_bqw_lf2_nt} {#r_GDT-getSpanTime_N__table_cqw_lf2_nt__entry__2}

| Type | Description |
|-|-|
| GlideTime | The amount of time elapsed since midnight of the specified day. To display the result in user-friendly terms, set the value to GlideDuration. |
[Tabelle : 87. Returns]

{#r_GDT-getSpanTime_N__table_cqw_lf2_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00"); //Wednesday
    var dur = new GlideDuration();
     
    var span = gdt.getSpanTime(1); //how much time since Monday 00:00:00
    dur.setValue(span);
    gs.print(dur.getDisplayValue());

Output:

    2 Days 8 Hours

## GlideDateTime - getTime() {#ariaid-title47}

Gets the Unix duration stamp.
{#r_GDT-getTime__table_lny_z42_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 88. Parameters]

{#r_GDT-getTime__table_lny_z42_nt} {#r_GDT-getTime__table_mny_z42_nt__entry__2}

| Type | Description |
|-|-|
| GlideTime | The Unix duration stamp in system format based on GMT time. |
[Tabelle : 89. Returns]

{#r_GDT-getTime__table_mny_z42_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gs.print(gdt.getTime());

Output:

    1970-01-01 08:00:00

### Scoped equivalent {#r_GDT-getTime__section_fjc_xvr_mcb}

To use the getTime() method in a scoped application, use the
corresponding scoped method: [getTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetTime "Returns a GlideTime object that represents the time portion of the GlideDateTime object.").

## GlideDateTime - getTZOffset() {#ariaid-title48}

Gets the time zone offset in milliseconds.
{#r_GDT-getTZOffset__table_nk4_f5l_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 90. Parameters]

{#r_GDT-getTZOffset__table_nk4_f5l_nt} {#r_GDT-getTZOffset__table_ok4_f5l_nt__entry__2}

| Type | Description |
|-|-|
| Number | The number of milliseconds of the time zone offset |
[Tabelle : 91. Returns]

{#r_GDT-getTZOffset__table_ok4_f5l_nt}  

    var gdt = new GlideDateTime();
    gdt.getLocalTime(); // PST local time
    gs.print(gdt.getTZOffset());

Output:

    -28800000

### Scoped equivalent {#r_GDT-getTZOffset__section_ihs_5vr_mcb}

To use the getTZOffset() method in a scoped application, use the
corresponding scoped method: [getTZOffset()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetTZOffset "Gets the time zone offset in milliseconds.").

## GlideDateTime - getUserFormattedLocalTime() {#ariaid-title49}

Returns the object's time in local time zone in the user's format.
{#r_GDT-getUserFormattedLocalTime__table_lgj_ftc_kw__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 92. Parameters]

{#r_GDT-getUserFormattedLocalTime__table_lgj_ftc_kw} {#r_GDT-getUserFormattedLocalTime__table_mgj_ftc_kw__entry__2}

| Type | Description |
|-|-|
| Object | The object's time in local time and the user's format. |
[Tabelle : 93. Returns]

{#r_GDT-getUserFormattedLocalTime__table_mgj_ftc_kw}  
The following code example shows how to call this method.

    var gdt = new GlideDateTime('2022-10-08 01:00:00');
    gs.info(gdt.getDisplayValue());
    gs.info(gdt.getUserFormattedLocalTime());

Output:

    2022-10-07 06:00:00 PM
    06:00:00 PM

### Scoped equivalent {#r_GDT-getUserFormattedLocalTime__section_hsv_f22_dbb}

To use the getUserFormattedLocalTime() method in a scoped application,
use the corresponding scoped method: [getUserFormattedLocalTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_SGDT-getUserFormattedLocalTime "Returns the object's time in the local time zone and in the user's format.").

## GlideDateTime - getUserTimeZone() {#ariaid-title50}

Retrieves the time zone for the current user session.
This method is equivalent to `gs.getSession().getTimeZone()`.
{#r_GDT-getUserTimeZone__table_eyw_b4c_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 94. Parameters]

{#r_GDT-getUserTimeZone__table_eyw_b4c_nt} {#r_GDT-getUserTimeZone__table_fyw_b4c_nt__entry__2}

| Type | Description |
|-|-|
| TimeZone | TimeZone object for the current user. |
[Tabelle : 95. Returns]

{#r_GDT-getUserTimeZone__table_fyw_b4c_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gs.print(gdt.getUserTimeZone());

Output:

    sun.util.calendar.ZoneInfo[id="America/Los_Angeles",offset=-28800000,dstSavings=3600000,useDaylight=true,transitions=185,
    lastRule=java.util.SimpleTimeZone[id=America/Los_Angeles,offset=-28800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,
    startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,
    endTime=7200000,endTimeMode=0]]

## GlideDateTime - getUTCMidnight(Number dayOfTheWeek) {#ariaid-title51}

Retrieves a GlideDateTime object with the time set to midnight using the UTC time zone.
This method sets the date of the new GlideDateTime object as the specified day of the week
within the week of the original GlideDateTime object.
{#r_GDT-getUTCMidnight_N__table_ezg_zp2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| dayOfTheWeek | Number | The day of the week, from 1 to 7. Monday=1, Sunday=7. Do not enter 0 in this parameter. |
[Tabelle : 96. Parameters]

{#r_GDT-getUTCMidnight_N__table_ezg_zp2_nt} {#r_GDT-getUTCMidnight_N__table_fzg_zp2_nt__entry__2}

| Type | Description |
|-|-|
| GlideDateTime | A new GlideDateTime object, set to midnight. |
[Tabelle : 97. Returns]

{#r_GDT-getUTCMidnight_N__table_fzg_zp2_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00"); // Wednesday, 3rd day of the week.
    gs.print(gdt.getUTCMidnight(5)); //Friday, 5th day of the week.

Output:

    2011-09-02 00:00:00

## GlideDateTime - getValue() {#ariaid-title52}

Returns the date and time value stored by the GlideDateTime object in the internal format, yyyy-MM-dd HH:mm:ss, in the UTC time zone.
{#r_GDT-getValue__table_osc_gbd_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 98. Parameters]

{#r_GDT-getValue__table_osc_gbd_nt} {#r_GDT-getValue__table_psc_gbd_nt__entry__2}

| Type | Description |
|-|-|
| String | Date and time in the internal format and system time zone. Format: yyyy-MM-dd HH:mm:ss in the UTC time zone. |
[Tabelle : 99. Returns]

{#r_GDT-getValue__table_psc_gbd_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gs.info(gdt.getValue());

Output:

    2011-08-31 08:00:00

### Scoped equivalent {#r_GDT-getValue__section_kt5_zvr_mcb}

To use the getValue() method in a scoped application, use the
corresponding scoped method: [getValue()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetValue "Returns the date and time value stored by the GlideDateTime object in the internal format, yyyy-MM-dd HH:mm:ss, in the UTC time zone.").

## GlideDateTime - getWeekOfYearLocalTime() {#ariaid-title53}

Gets the number of the week stored by the GlideDateTime object, expressed in the
current user's time zone.
All weeks begin on Sunday. The first week of the year is the week that contains at least
one day of the new year. The week beginning Sunday 2015-12-27 is considered the first week
of 2016 as that week contains January 1 and 2.
{#r_GDT-getWeekOfYearLocalTime__table_vq5_422_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 100. Parameters]

{#r_GDT-getWeekOfYearLocalTime__table_vq5_422_nt} {#r_GDT-getWeekOfYearLocalTime__table_wq5_422_nt__entry__2}

| Type | Description |
|-|-|
| Number | The number of the current week. The highest week number in a year is either 52 or 53. |
[Tabelle : 101. Returns]

{#r_GDT-getWeekOfYearLocalTime__table_wq5_422_nt}  

    var gdt = new GlideDateTime("2011-12-01 12:00:00");
    gs.print(gdt.getWeekOfYearUTC());

Output:

    49

### Scoped equivalent {#r_GDT-getWeekOfYearLocalTime__section_yh2_cwr_mcb}

To use the getWeekOfYearLocalTime() method in a scoped application, use
the corresponding scoped method: [getWeekOfYearLocalTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetWeekOfYearLocalTime "Gets the number of the week stored by the GlideDateTime object, expressed in the current user's time zone.").

## GlideDateTime - getWeekOfYearUTC() {#ariaid-title54}

Gets the number of the week stored by the GlideDateTime object, expressed in the UTC
time zone.
All weeks begin on Sunday. The first week of the year is the week that contains at least
one day of the new year. The week beginning Sunday 2015-12-27 is considered the first week
of 2016 as that week contains January 1 and 2.
{#r_GDT-getWeekOfYearUTC__table_jdh_bf2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 102. Parameters]

{#r_GDT-getWeekOfYearUTC__table_jdh_bf2_nt} {#r_GDT-getWeekOfYearUTC__table_kdh_bf2_nt__entry__2}

| Type | Description |
|-|-|
| Number | The number of the current week in UTC time. The highest week number in a year is either 52 or 53. |
[Tabelle : 103. Returns]

{#r_GDT-getWeekOfYearUTC__table_kdh_bf2_nt}  

    var gdt = new GlideDateTime("2011-12-01 12:00:00");
    gs.print(gdt.getWeekOfYearUTC());

Output:

    49

### Scoped equivalent {#r_GDT-getWeekOfYearUTC__section_fpl_2wr_mcb}

To use the getWeekOfYearUTC() method in a scoped application, use the
corresponding scoped method: [getWeekOfYearUTC()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetWeekOfYearUTC "Gets the number of the week stored by the GlideDateTime object, expressed in the UTC time zone.").

## GlideDateTime - getYear() {#ariaid-title55}

Retrieves the year stored by the GlideDateTime object, expressed in the Java Virtual
Machine time zone.
Use getYearLocalTime() and getYearUTC() instead of
this method.
{#r_GDT-getYear__table_jhh_dn2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 104. Parameters]

{#r_GDT-getYear__table_jhh_dn2_nt} {#r_GDT-getYear__table_khh_dn2_nt__entry__2}

| Type | Description |
|-|-|
| Number | The 4-digit year value in the Java Virtual Machine time zone. |
[Tabelle : 105. Returns]

{#r_GDT-getYear__table_khh_dn2_nt}  

    var gdt = new GlideDateTime(); //2011
    gs.print(gdt.getYear());

Output:

    2011

## GlideDateTime - getYearLocalTime() {#ariaid-title56}

Gets the year stored by the GlideDateTime object, expressed in the current user's time
zone.
{#r_GDT-getYearLocalTime__table_tzz_4n2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 106. Parameters]

{#r_GDT-getYearLocalTime__table_tzz_4n2_nt} {#r_GDT-getYearLocalTime__table_uzz_4n2_nt__entry__2}

| Type | Description |
|-|-|
| Number | The 4-digit year value in the user's time zone. |
[Tabelle : 107. Returns]

{#r_GDT-getYearLocalTime__table_uzz_4n2_nt}  

    var gdt = new GlideDateTime(); //2011
    gs.print(gdt.getYearLocalTime());

Output:

    2011

### Scoped equivalent {#r_GDT-getYearLocalTime__section_dys_jwr_mcb}

To use the getYearLocalTime() method in a scoped application, use the
corresponding scoped method: [getYearLocalTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetYearLocalTime "Gets the year stored by the GlideDateTime object, expressed in the current user's time zone.").

## GlideDateTime - getYearUTC() {#ariaid-title57}

Returns the year stored by the GlideDateTime object, expressed in the UTC time
zone.
{#r_GDT-getYearUTC__table_dml_xn2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 108. Parameters]

{#r_GDT-getYearUTC__table_dml_xn2_nt} {#r_GDT-getYearUTC__table_eml_xn2_nt__entry__2}

| Type | Description |
|-|-|
| number | Four-digit year value in the UTC time zone. |
[Tabelle : 109. Returns]

{#r_GDT-getYearUTC__table_eml_xn2_nt}  

    var gdt = new GlideDateTime(); //2011
    gs.info(gdt.getYearUTC());

Output:

    2011

### Scoped equivalent {#r_GDT-getYearUTC__section_j4m_pwr_mcb}

To use the getYearUTC() method in a scoped application, use the
corresponding scoped method: [getYearUTC()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeGetYearUTC "Gets the year stored by the GlideDateTime object, expressed in the UTC time zone.").

## GlideDateTime - hasDate() {#ariaid-title58}

Determines if an object's date is set.
{#r_GDT-hasDate__table_iqj_rnc_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 110. Parameters]

{#r_GDT-hasDate__table_iqj_rnc_nt} {#r_GDT-hasDate__table_jqj_rnc_nt__entry__2}

| Type | Description |
|-|-|
| Boolean | True if the object's date is set, false otherwise. |
[Tabelle : 111. Returns]

{#r_GDT-hasDate__table_jqj_rnc_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gs.print(gdt.hasDate());

Output:

    true

### Scoped equivalent {#r_GDT-hasDate__section_yzp_rwr_mcb}

To use the hasDate() method in a scoped application, use the
corresponding scoped method: [hasDate()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeHasDate "Determines if an object's date is set.").

## GlideDateTime - isDST() {#ariaid-title59}

Determines if the object's time uses a daylight saving offset
{#r_GDT-isDST__table_ncy_jvc_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 112. Parameters]

{#r_GDT-isDST__table_ncy_jvc_nt} {#r_GDT-isDST__table_ocy_jvc_nt__entry__2}

| Type | Description |
|-|-|
| Boolean | True if the time is daylight saving time, false otherwise. |
[Tabelle : 113. Returns]

{#r_GDT-isDST__table_ocy_jvc_nt}  

    var gdt = new GlideDateTime("2011-08-31 00:00:00");
    gs.print(gdt.isDST()); //true

Output:

    true

### Scoped equivalent {#r_GDT-isDST__section_gns_twr_mcb}

To use the isDST() method in a scoped application, use the corresponding
scoped method: [isDST()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeIsDST "Determines if an object's time uses a daylight saving offset.").

## GlideDateTime - isValid() {#ariaid-title60}

Determines if a value is a valid date and time.
{#r_GDT-isValid__table_sfh_5rl_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 114. Parameters]

{#r_GDT-isValid__table_sfh_5rl_nt} {#r_GDT-isValid__table_tfh_5rl_nt__entry__2}

| Type | Description |
|-|-|
| Boolean | True if value is valid, false otherwise. |
[Tabelle : 115. Returns]

{#r_GDT-isValid__table_tfh_5rl_nt}  

    var gdt = new GlideDateTime("2011-aa-31 aa:00:00"); 
    gs.print(gdt.isValid()); //true
    gs.print(gdt.getErrorMsg()); //reason

Output

    Invalid date time: '2011-aa-31 aa:00:00', ignored

### Scoped equivalent {#r_GDT-isValid__section_flp_vwr_mcb}

To use the isValid() method in a scoped application, use the
corresponding scoped method: [isValid()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeIsValid "Determines if a value is a valid date and time.").

## GlideDateTime - setDayOfMonth(Number day) {#ariaid-title61}

Sets the day of the month to a specified value.
Use setDayOfMonthLocalTime(day) and
setDayOfMonthUTC(day) instead of this method.
{#r_GDT-setDayOfMonth_N__table_pp4_vh2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| day | Number | Day of the month, from 1 to 31. |
[Tabelle : 116. Parameters]

{#r_GDT-setDayOfMonth_N__table_pp4_vh2_nt} {#r_GDT-setDayOfMonth_N__table_qp4_vh2_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 117. Returns]

{#r_GDT-setDayOfMonth_N__table_qp4_vh2_nt}  

    var gdt = new GlideDateTime();
    gdt.setDayOfMonth(9);
    gs.print(gdt.getDayOfMonth());

Output:

    9

## GlideDateTime - setDayOfMonthLocalTime(Number day) {#ariaid-title62}

Sets the day of the month to a specified value in the current user's time zone.
{#r_GDT-setDayOfMonthLocalTime_N__table_bvc_1j2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| day | Number | The day of month to change to, from 1 to 31. If this value is greater than the maximum number of days in the month, the value is set to the last day of the month. |
[Tabelle : 118. Parameters]

{#r_GDT-setDayOfMonthLocalTime_N__table_bvc_1j2_nt} {#r_GDT-setDayOfMonthLocalTime_N__table_cvc_1j2_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 119. Returns]

{#r_GDT-setDayOfMonthLocalTime_N__table_cvc_1j2_nt}  

    var gdt = new GlideDateTime();
    gdt.setDayOfMonthLocalTime(9);
    gs.print(gdt.getDayOfMonthLocalTime());

Output:

    9

### Scoped equivalent {#r_GDT-setDayOfMonthLocalTime_N__section_p4c_ywr_mcb}

To use the setDayOfMonthLocalTime() method in a scoped application, use
the corresponding scoped method: [setDayOfMonthLocalTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeSetDayOfMonthLocalTime_Number_day "Sets the day of the month to a specified value in the current user's time zone.").

## GlideDateTime - setDayOfMonthUTC(Number day) {#ariaid-title63}

Sets the day of the month to a specified value in the UTC time zone.
{#r_GDT-setDayOfMonthUTC_N__table_mmk_mj2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| day | Number | The day of month to change to, from 1 to 31. If this value is greater than the maximum number of days in the month, the value is set to the last day of the month. |
[Tabelle : 120. Parameters]

{#r_GDT-setDayOfMonthUTC_N__table_mmk_mj2_nt} {#r_GDT-setDayOfMonthUTC_N__table_nmk_mj2_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 121. Returns]

{#r_GDT-setDayOfMonthUTC_N__table_nmk_mj2_nt}  

    var gdt = new GlideDateTime();
    gdt.setDayOfMonthUTC(9);
    gs.print(gdt.getDayOfMonthUTC());

Output:

    9

### Scoped equivalent {#r_GDT-setDayOfMonthUTC_N__section_rxh_1xr_mcb}

To use the setDayOfMonthUTC() method in a scoped application, use the
corresponding scoped method: [setDayOfMonthUTC()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeSetDayOfMonthUTC_Number_day "Sets the day of the month to a specified value in the UTC time zone.").

## GlideDateTime - setDisplayValue(String asDisplayed) {#ariaid-title64}

Sets a date and time value using the current user's display format and time
zone.
{#r_GDT-setDisplayValue_S__table_jnc_fwc_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| asDisplayed | String | The date and time in the current user's display format and time zone. The parameter must be formatted using the current user's preferred display format, such as MM-dd-yyyy HH:mm:ss. To assign the current date and time to a variable in a workflow script, use `<variable>.setDisplayValue(gs.nowDateTime);`. |
[Tabelle : 122. Parameters]

{#r_GDT-setDisplayValue_S__table_jnc_fwc_nt} {#r_GDT-setDisplayValue_S__table_knc_fwc_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 123. Returns]

{#r_GDT-setDisplayValue_S__table_knc_fwc_nt}  

    var gdt = new GlideDateTime("2011-02-02 12:00:00");
    gdt.setDisplayValue("2011-01-01 12:00:00");
    gs.print(gdt.getValue());

Output:

    2011-01-01 20:00:00

### Scoped equivalent {#r_GDT-setDisplayValue_S__section_wyq_2xr_mcb}

To use the setDisplayValue() method in a scoped application, use the
corresponding scoped method: [setDisplayValue()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeSetDisplayValue_String_asDisplayed "Sets a date and time value using the current user's display format and time zone.").

## GlideDateTime - setDisplayValue(String dateTime, String format) {#ariaid-title65}

Sets a date and time value using the current user's time zone and the specified date
and time format.
This method throws a runtime exception if the date and time format used in the dateTime
parameter does not match the format parameter. You can retrieve the error message by calling
getErrorMsg() on the GlideDateTime object after the exception is
caught.
{#r_GDT-setDisplayValue_S_S__table_dqz_pzc_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| dateTime | String | The date and time in the current user's time zone. |
| format | String | The format to use to parse the dateTime parameter. |
[Tabelle : 124. Parameters]

{#r_GDT-setDisplayValue_S_S__table_dqz_pzc_nt} {#r_GDT-setDisplayValue_S_S__table_eqz_pzc_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 125. Returns]

{#r_GDT-setDisplayValue_S_S__table_eqz_pzc_nt}  

    var gdt = new GlideDateTime("2011-02-02 12:00:00");
    gdt.setDisplayValue("20-5-2011 12:00:00", "dd-MM-yyyy HH:mm:ss");
    gs.print(gdt.getValue());

Output:

    2011-05-20 19:00:00

### Scoped equivalent {#r_GDT-setDisplayValue_S_S__section_zns_gxr_mcb}

To use the setDisplayValue() method in a scoped application, use the
corresponding scoped method: [setDisplayValue()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeSetDisplayValue_String_value_String_format "Sets a date and time value using the current user's time zone and the specified date and time format.").

## GlideDateTime - setDisplayValueInternal(String dateTime) {#ariaid-title66}

Sets a date and time value using the internal format (yyyy-MM-dd HH:mm:ss) and the
current user's time zone.
{#r_GDT-setDisplayValueInternal_S__table_zrg_5wc_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| dateTime | String | The date and time in internal format |
[Tabelle : 126. Parameters]

{#r_GDT-setDisplayValueInternal_S__table_zrg_5wc_nt} {#r_GDT-setDisplayValueInternal_S__table_asg_5wc_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 127. Returns]

{#r_GDT-setDisplayValueInternal_S__table_asg_5wc_nt}  

    var gdt = new GlideDateTime("2011-02-02 12:00:00");
    gdt.setDisplayValueInternal("2011-01-01 12:00:00");
    gs.print(gdt.getValue());

Output:

    2011-01-01 20:00:00

### Scoped equivalent {#r_GDT-setDisplayValueInternal_S__section_hrc_cxr_mcb}

To use the setDisplayValueInternal() method in a scoped application, use
the corresponding scoped method: [setDisplayValueInternal()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeSetDisplayValueInternal_String_value "Sets a date and time value using the internal format (yyyy-MM-dd HH:mm:ss) and the current user's time zone.").

## GlideDateTime - setDisplayValueInternalWithAlternates(String dateTime) {#ariaid-title67}

Sets a date and time value using the internal format (yyyy-MM-dd HH:mm:ss) and the
current user's time zone.
This method attempts to parse incomplete date and time values.
{#r_GDT-setDispValInternalAlt_S__table_ipl_dzc_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| dateTime | String | The date and time in internal format. |
[Tabelle : 128. Parameters]

{#r_GDT-setDispValInternalAlt_S__table_ipl_dzc_nt} {#r_GDT-setDispValInternalAlt_S__table_jpl_dzc_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 129. Returns]

{#r_GDT-setDispValInternalAlt_S__table_jpl_dzc_nt}

## GlideDateTime - setDisplayValueLang(String dateTime, String style) {#ariaid-title68}

Sets a date using a specified style and format according to the current user's
locale.
{#r_GDT-setDisplayValueLang_S_S__id_jjl_xvw_dwb__entry__3}

| Name | Type | Description |
|-|-|-|
| dateTime | String | Date and time value for the GlideDate object in the current user's time zone. Valid values are any date and time output from the getDisplayValueLang() function. For instance, using output from the getDisplayValueLang(String style, String language) example earlier in this topic, November 28, 2022 07:03:41 or 28.11.2022 07:03:41 are accepted values. |
| style | String | Specifies the date format. Valid values: * full: returns the date in the format of \<weekday, month, day, and year\> according to the user's locale (for example, Monday, October 24, 2022). * long: returns the date in the format of \<month, day, and year\> according to the user's locale (for example, October 24, 2022). * medium: similar to long but returns the date with an abbreviated month (for example, Oct 24, 2022). * short: returns the date in the format of MM/DD/YY or DD/MM/YY according to the user's locale (for example, 10/24/2022 or 24/10/2022). If any other value is passed the API will default to use <var class="keyword varname">medium</var>. Accepted values are not case sensitive. |
[Tabelle : 130. Parameters]

{#r_GDT-setDisplayValueLang_S_S__id_jjl_xvw_dwb} {#r_GDT-setDisplayValueLang_S_S__id_e41_yvw_dwb__entry__2}

| Type | Description |
|-|-|
| Void |   |
[Tabelle : 131. Returns]

{#r_GDT-setDisplayValueLang_S_S__id_e41_yvw_dwb}  
The following example returns the date and time in short and full styles.

    var glideDateFR = new GlideDateTime();
    glideDateFR.setDisplayValueLang("2/3/2023 17:27:56", "short");

    gs.info('date: ' + glideDateFR.getDisplayValue());
    gs.info('date: ' + glideDateFR.getDisplayValueLang("full"));

Output:

    date: 2023-02-03 17:27:56
    date: Friday, February 3, 2023 17:27:56

## GlideDateTime - setDisplayValueLang(String dateTime, String style, String language) {#ariaid-title69}

Sets a date and time using a specified style, language, and format according to the
current user's locale.
{#r_GDT-setDisplayValueLang_S_S_S__id_zks_2ww_dwb__entry__3}

| Name | Type | Description |
|-|-|-|
| dateTime | String | Date and time value for the GlideDate object in the current user's time zone. Valid values are any date and time output from the getDisplayValueLang() function. For instance, using output from the getDisplayValueLang(String style, String language) example earlier in this topic, November 28, 2022 07:03:41 or 28.11.2022 07:03:41 are accepted values. |
| style | String | Specifies the date format. Valid values: * full: returns the date in the format of \<weekday, month, day, and year\> according to the user's locale (for example, Monday, October 24, 2022). * long: returns the date in the format of \<month, day, and year\> according to the user's locale (for example, October 24, 2022). * medium: similar to long but returns the date with an abbreviated month (for example, Oct 24, 2022). * short: returns the date in the format of MM/DD/YY or DD/MM/YY according to the user's locale (for example, 10/24/2022 or 24/10/2022). If any other value is passed the API will default to use <var class="keyword varname">medium</var>. Accepted values are not case sensitive. |
| language | String | Sets the language using a language tag that conforms with the BCP-47 standard. For example, `fr` for French or `en-UK` for British English. For a full list of accepted values, see [BCP 47 Language Code List](https://appmakers.dev/bcp-47-language-codes-list/). |
[Tabelle : 132. Parameters]

{#r_GDT-setDisplayValueLang_S_S_S__id_zks_2ww_dwb} {#r_GDT-setDisplayValueLang_S_S_S__id_rg3_fww_dwb__entry__2}

| Type | Description |
|-|-|
| Void |   |
[Tabelle : 133. Returns]

{#r_GDT-setDisplayValueLang_S_S_S__id_rg3_fww_dwb}  
The following example returns the date and time in short and full styles for English and
French.

    var glideDateFR = new GlideDateTime(); 

    glideDateUS.setDisplayValueLang("2/3/2023 18:00:00", "short", "en-US" );
    glideDateFR.setDisplayValueLang("2/3/2023 18:00:00", "short", "fr-FR" );

    gs.info('en-US date: ' + glideDateUS.getDisplayValue());
    gs.info('en-US date: ' + glideDateUS.getDisplayValueLang("full"));

    gs.info('fr-FR date: ' + glideDateFR.getDisplayValue());
    gs.info('fr-FR date: ' + glideDateFR.getDisplayValueLang("full"));

Output:

    en-US date: 2023-02-03 18:00:00
    en-US date: Friday, February 3, 2023 18:00:00
    fr-FR date: 2023-03-02 18:00:00
    fr-FR date: Thursday, March 2, 2023 18:00:00

## GlideDateTime - setGlideDateTime(GlideDateTime gDT) {#ariaid-title70}

Sets the date and time of the current object using an existing GlideDateTime object.
This method is equivalent to instantiating a new object with a GlideDateTime parameter.
{#r_GDT-setGlideDateTime_GDT__table_xdg_y5c_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| gDT | GlideDateTime | A GlideDateTime object |
[Tabelle : 134. Parameters]

{#r_GDT-setGlideDateTime_GDT__table_xdg_y5c_nt} {#r_GDT-setGlideDateTime_GDT__table_ydg_y5c_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 135. Returns]

{#r_GDT-setGlideDateTime_GDT__table_ydg_y5c_nt}  

    var dt1 = new GlideDateTime("2011-01-01 12:00:00");
    var dt2 = new GlideDateTime("2011-02-02 08:00:00");
    dt1.setGlideDateTime(dt2);
    gs.print(dt1.getValue());

Output:

    2011-02-02 08:00:00

### Scoped equivalent {#r_GDT-setGlideDateTime_GDT__section_fjw_3xr_mcb}

To use the setGlideDateTime() method in a scoped application, use the
corresponding scoped method: [setGlideDateTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeSetGlideDateTime_g "Sets the date and time of the current object using an existing GlideDateTime object. This method is equivalent to instantiating a new object with a GlideDateTime parameter.").

## GlideDateTime - setInitialValue(String dateTime) {#ariaid-title71}

Sets the date and time.
This method is equivalent to setValue(Object).
{#r_GDT-setInitialValue_S__table_i42_r5l_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| dateTime | String | The date and time to use. Accepts either a string in the GMT time zone in the internal format, or a GlideDateTime object. |
[Tabelle : 136. Parameters]

{#r_GDT-setInitialValue_S__table_i42_r5l_nt} {#r_GDT-setInitialValue_S__table_j42_r5l_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 137. Returns]

{#r_GDT-setInitialValue_S__table_j42_r5l_nt}  

    var gdt = new GlideDateTime();
    gdt.setInitialValue("2011-01-01 12:00:00");
    gs.print(gdt.getValue());

Output:

    2011-01-01 12:00:00

## GlideDateTime - setMonth(Number month) {#ariaid-title72}

Sets the month stored by the GlideDateTime object to a specified value using the Java
Virtual Machine time zone.
Use setMonthLocalTime() or setMonthUTC() instead of
this method.
{#r_GDT-setMonth_N__table_djd_3wl_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| month | Number | The month to change to. |
[Tabelle : 138. Parameters]

{#r_GDT-setMonth_N__table_djd_3wl_nt} {#r_GDT-setMonth_N__table_ejd_3wl_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 139. Returns]

{#r_GDT-setMonth_N__table_ejd_3wl_nt}  

    var gdt = new GlideDateTime();
    gdt.setMonth(1);
    gs.print(gdt.getMonth());

Output:

    1

## GlideDateTime - setMonthLocalTime(Number month) {#ariaid-title73}

Sets the month stored by the GlideDateTime object to a specified value using the
current user's time zone.
{#r_GDT-setMonthLocalTime_N__table_xgm_wwl_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| month | Number | The month to change to. |
[Tabelle : 140. Parameters]

{#r_GDT-setMonthLocalTime_N__table_xgm_wwl_nt} {#r_GDT-setMonthLocalTime_N__table_ygm_wwl_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 141. Returns]

{#r_GDT-setMonthLocalTime_N__table_ygm_wwl_nt}  

    var gdt = new GlideDateTime();
    gdt.setMonthLocalTime(1);
    gs.print(gdt.getMonthLocalTime());

Output:

    1

### Scoped equivalent {#r_GDT-setMonthLocalTime_N__section_rqq_lxr_mcb}

To use the setMonthLocalTime() method in a scoped application, use the
corresponding scoped method: [setMonthLocalTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeSetMonthLocalTime_Number "Sets the month stored by the GlideDateTime object to the specified value using the current user's time zone.").

## GlideDateTime - setMonthUTC(Number month) {#ariaid-title74}

Sets the month stored by the GlideDateTime object to a specified value using the UTC
time zone.
{#r_GDT-setMonthUTC_N__table_gt5_fxl_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| month | Number | The month to change to. |
[Tabelle : 142. Parameters]

{#r_GDT-setMonthUTC_N__table_gt5_fxl_nt} {#r_GDT-setMonthUTC_N__table_ht5_fxl_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 143. Returns]

{#r_GDT-setMonthUTC_N__table_ht5_fxl_nt}  

    var gdt = new GlideDateTime();
    gdt.setMonthUTC(1);
    gs.print(gdt.getMonthUTC());

Output:

    1

### Scoped equivalent {#r_GDT-setMonthUTC_N__section_xyx_nxr_mcb}

To use the setMonthUTC() method in a scoped application, use the
corresponding scoped method: [setMonthUTC()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeSetMonthUTC_Number "Sets the month stored by the GlideDateTime object to the specified value using the UTC time zone.").

## GlideDateTime - setNumericValue(Number milliseconds) {#ariaid-title75}

Sets the date and time to the number of milliseconds since January 1, 1970 00:00:00
GMT.
{#r_GDT-setNumericValue_N__table_jsf_q42_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| milliseconds | Number | Number of milliseconds |
[Tabelle : 144. Parameters]

{#r_GDT-setNumericValue_N__table_jsf_q42_nt} {#r_GDT-setNumericValue_N__table_ksf_q42_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 145. Returns]

{#r_GDT-setNumericValue_N__table_ksf_q42_nt}  

    var gdt = new GlideDateTime();
    gdt.setNumericValue(1314777600000);
    gs.print(gdt.getValue());

Output:

    2011-08-31 08:00:00

## GlideDateTime - setTZ(TimeZone timeZone) {#ariaid-title76}

Sets the time zone of the GlideDateTime object to be the specified time
zone.
{#r_GDT-setTZ_TZ__table_uy3_54c_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| timeZone | TimeZone | A time zone object |
[Tabelle : 146. Parameters]

{#r_GDT-setTZ_TZ__table_uy3_54c_nt} {#r_GDT-setTZ_TZ__table_vy3_54c_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 147. Returns]

{#r_GDT-setTZ_TZ__table_vy3_54c_nt}  

    var tz = gs.getSession().getTimeZone();
    var gdt = new GlideDateTime(); 
    gdt.setTZ(tz);

## GlideDateTime - setValue(Object dateTime) {#ariaid-title77}

Sets the date and time of the GlideDateTime object.
This method is equivalent to setInitialValue().
{#r_GDT-setValue_O__table_yfh_fpc_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| dateTime | Object | The date and time to use. This parameter may be one of several types. * A string in the UTC time zone and the internal format of yyyy-MM-dd HH:mm:ss: Sets the value of the object to the specified date and time. Using the method this way is equivalent to instantiating a new GlideDateTime object using the GlideDateTime(value) constructor. If the date and time format used does not match the internal format, the method attempts to set the date and time using other available formats. Resolving the date and time this way can lead to inaccurate data due to ambiguity in the day and month values. When using a non-standard date and time format, use setValueUTC(dateTime, format) instead. * A GlideDateTime object: Sets the value of the object to the date and time stored by the GlideDateTime passed in the parameter. Using the method this way is equivalent to instantiating a new GlideDateTime object using the GlideDateTime(g) constructor. * A Java Date object: Sets the value of the object using the value stored by the Java Date object. Using the method this way is equivalent to passing the value returned by the Java Date object getTime() to the GlideDateTime setNumericValue() method. This method does not accept JavaScript Date objects. * A JavaScript Number: Sets the value of the object using the Number value as milliseconds past January 1, 1970 00:00:00 UTC. Using the method this way is equivalent to the setNumericValue(milliseconds) method. * A Java Integer or Long: Sets the value of the object using the Integer or Long value as milliseconds past January 1, 1970 00:00:00 UTC. Using the method this way is equivalent to the setNumericValue(milliseconds) method. {#r_GDT-setValue_O__ul_j3h_4pc_nt} |
[Tabelle : 148. Parameters]

{#r_GDT-setValue_O__table_yfh_fpc_nt} {#r_GDT-setValue_O__table_zfh_fpc_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 149. Returns]

{#r_GDT-setValue_O__table_zfh_fpc_nt}  
Set the date and time using a string in yyyy-MM-dd HH:mm:ss format.

    var gdt = new GlideDateTime("2011-01-01 12:00:00");
    gdt.setValue("2011-02-02 08:00:00");
    gs.print(gdt.getValue());

Output:

    2011-02-02 08:00:00

Set the date and time using an existing GlideDateTime object.

    var gdtSource = new GlideDateTime("2017-05-23 11:37:41");
    var gdtDest = new GlideDateTime();
    gdtDest.setValue(gdtSource);
    gs.print(gdtDest.getValue());

Output:

    2017-05-23 11:37:41

Set the date and time using a number indicating milliseconds past January 1, 1970 00:00:00 UTC.

    var gdt = new GlideDateTime("2011-01-01 12:00:00");
    gdt.setValue(1617634522375);
    gs.print(gdt.getValue());

Output:

    2021-04-05 14:55:22

### Scoped equivalent {#r_GDT-setValue_O__section_w2m_sxr_mcb}

To use the setValue() method in a scoped application, use the
corresponding scoped method: [setValue()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeSetValue_String_o "Sets the date and time of the GlideDateTime object.").

## GlideDateTime - setValueUTC(String dateTime, String format) {#ariaid-title78}

Sets a date and time value using the UTC time zone and the specified date and time
format.
This method throws a runtime exception if the date and time format used in the dateTime
parameter does not match the format parameter. You can retrieve the error message by calling
getErrorMsg() on the GlideDateTime object after the exception is
caught.
{#r_GDT-setValueUTC_S_S__table_p5w_35c_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| dateTime | String | The date and time to use. |
| format | String | The format to use. |
[Tabelle : 150. Parameters]

{#r_GDT-setValueUTC_S_S__table_p5w_35c_nt} {#r_GDT-setValueUTC_S_S__table_q5w_35c_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 151. Returns]

{#r_GDT-setValueUTC_S_S__table_q5w_35c_nt}  

    var gdt = new GlideDateTime("2011-01-01 12:00:00");
    gdt.setValueUTC("15-02-2011 08:00:00", "dd-MM-yyyy HH:mm:ss");
    gs.print(gdt.getValue());

Output:

    2011-02-15 08:00:00

### Scoped equivalent {#r_GDT-setValueUTC_S_S__section_ft1_qxr_mcb}

To use the setValueUTC() method in a scoped application, use the
corresponding scoped method: [setValueUTC()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeSetValueUTC_String_dt_String_format "Sets a date and time value using the UTC time zone and the specified date and time format. This method throws a runtime exception if the date and time format used in the dt parameter does not match the format parameter. You can retrieve the error message by calling getErrorMsg() on the GlideDateTime object after the exception is caught.").

## GlideDateTime - setYear(Number year) {#ariaid-title79}

Sets the year stored by the GlideDateTime object to a specified value using the Java
Virtual Machine time zone.
Use setYearLocalTime() or setYearUTC() instead of
this method.
{#r_GDT-setYear_N__table_tgf_4xl_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| year | Number | The year to change to. |
[Tabelle : 152. Parameters]

{#r_GDT-setYear_N__table_tgf_4xl_nt} {#r_GDT-setYear_N__table_ugf_4xl_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 153. Returns]

{#r_GDT-setYear_N__table_ugf_4xl_nt}  

    var gdt = new GlideDateTime();
    gdt.setYear(2013);
    gs.print(gdt.getYear());

Output:

    2013

## GlideDateTime - setYearLocalTime(Number year) {#ariaid-title80}

Sets the year stored by the GlideDateTime object to a specified value using the current
user's time zone.
{#r_GDT-setYearLocalTime_N__table_vp4_1yl_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| year | Number | The year to change to. |
[Tabelle : 154. Parameters]

{#r_GDT-setYearLocalTime_N__table_vp4_1yl_nt} {#r_GDT-setYearLocalTime_N__table_wp4_1yl_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 155. Returns]

{#r_GDT-setYearLocalTime_N__table_wp4_1yl_nt}  

    var gdt = new GlideDateTime();
    gdt.setYearLocalTime(2013);
    gs.print(gdt.getYearLocalTime());

Output:

    2013

### Scoped equivalent {#r_GDT-setYearLocalTime_N__section_mjw_5xr_mcb}

To use the setYearLocalTime() method in a scoped application, use the
corresponding scoped method: [setYearLocalTime()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeSetYearLocalTime_Number "Sets the year stored by the GlideDateTime object to the specified value using the current user's time zone.").

## GlideDateTime - setYearUTC(Number year) {#ariaid-title81}

Sets the year stored by the GlideDateTime object to a specified value using the UTC
time zone.
{#r_GDT-setYearUTC_N__table_fzh_jyl_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| year | Number | The year to change to. |
[Tabelle : 156. Parameters]

{#r_GDT-setYearUTC_N__table_fzh_jyl_nt} {#r_GDT-setYearUTC_N__table_gzh_jyl_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 157. Returns]

{#r_GDT-setYearUTC_N__table_gzh_jyl_nt}  

    var gdt = new GlideDateTime();
    gdt.setYearUTC(2013);
    gs.print(gdt.getYearUTC());

Output:

    2013

### Scoped equivalent {#r_GDT-setYearUTC_N__section_q3v_wxr_mcb}

To use the setYearUTC() method in a scoped application, use the
corresponding scoped method: [setYearUTC()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeSetYearUTC_Number "Sets the year stored by the GlideDateTime object to the specified value using the UTC time zone.").

## GlideDateTime - subtract(GlideTime time) {#ariaid-title82}

Subtracts a specified amount of time.
{#r_GDT-subtract_GT__table_lsb_nzk_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| time | GlideTime | The time to subtract |
[Tabelle : 158. Parameters]

{#r_GDT-subtract_GT__table_lsb_nzk_nt} {#r_GDT-subtract_GT__table_msb_nzk_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 159. Returns]

{#r_GDT-subtract_GT__table_msb_nzk_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    var gtime1 = new GlideTime();
    gtime1.setValue("00:00:20");
    gdt.subtract(gtime1);
    gs.print(gdt.getTime());

Output:

    1970-01-01 07:59:40

### Scoped equivalent {#r_GDT-subtract_GT__section_ltp_byr_mcb}

To use the subtract() method in a scoped application, use the
corresponding scoped method: [subtract()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeSubtract_GlideTime "Subtracts a specified amount of time from the current GlideDateTime object.").

## GlideDateTime - subtract(Number milliseconds) {#ariaid-title83}

Subtracts a specified number of milliseconds from the GlideDateTime object.
{#r_GDT-subtract_N__table_r54_mtl_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| milliseconds | Number | The number of milliseconds to subtract |
[Tabelle : 160. Parameters]

{#r_GDT-subtract_N__table_r54_mtl_nt} {#r_GDT-subtract_N__table_s54_mtl_nt__entry__2}

| Type | Description |
|-|-|
| void |   |
[Tabelle : 161. Returns]

{#r_GDT-subtract_N__table_s54_mtl_nt}  

    var gdt = new GlideDateTime("2011-12-07 08:00:00");
    gdt.subtract(1000);
    gs.print(gdt.getValue());

Output:

    2011-12-07 07:59:59

### Scoped equivalent {#r_GDT-subtract_N__section_ihx_qyr_mcb}

To use the subtract() method in a scoped application, use the
corresponding scoped method: [subtract()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeSubtract_Number "Subtracts the specified number of milliseconds from the GlideDateTime object.").

## GlideDateTime - subtract(GlideDateTime start, GlideDateTime end) {#ariaid-title84}

Returns the duration difference between two specified GlideDateTime
objects.
{#r_GDT-subtract_GDT_GDT__table_gn2_grl_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| start | GlideDateTime | Start date object. |
| end | GlideDateTime | End date object. |
[Tabelle : 162. Parameters]

{#r_GDT-subtract_GDT_GDT__table_gn2_grl_nt} {#r_GDT-subtract_GDT_GDT__table_hn2_grl_nt__entry__2}

| Type | Description |
|-|-|
| GlideDuration | Duration difference between the two specified dates. |
[Tabelle : 163. Returns]

{#r_GDT-subtract_GDT_GDT__table_hn2_grl_nt}  

    var gdt1 = new GlideDateTime("2011-08-28 09:00:00");
    var gdt2 = new GlideDateTime("2011-08-31 08:00:00");
     
    var dur = GlideDateTime.subtract(gdt1, gdt2); // Difference between gdt1 and gdt2
    gs.info(dur.getDisplayValue());

Output:

    2 Days 23 Hours

### Scoped equivalent {#r_GDT-subtract_GDT_GDT__section_apm_zxr_mcb}

To use the subtract() method in a scoped application, use the
corresponding scoped method: [subtract()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeSubtract_GlideDateTime_GlideDate_Time "Returns the duration difference between two specified GlideDateTime objects.").

## GlideDateTime - toString() {#ariaid-title85}

Returns the date and time value stored by the GlideDateTime object in the internal
format, yyyy-MM-dd HH:mm:ss, and the system time zone, UTC by default.
This method is equivalent to getValue().
{#r_GDT-toString__table_lyw_ls2_nt__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabelle : 164. Parameters]

{#r_GDT-toString__table_lyw_ls2_nt} {#r_GDT-toString__table_myw_ls2_nt__entry__2}

| Type | Description |
|-|-|
| Object | The date and time stored by the GlideDateTime object in the system time zone and format. |
[Tabelle : 165. Returns]

{#r_GDT-toString__table_myw_ls2_nt}  

    var gdt = new GlideDateTime("2011-08-31 08:00:00");
    gs.print(gdt.toString());

Output:

    2011-08-31 08:00:00

### Scoped equivalent {#r_GDT-toString__section_fxf_tyr_mcb}

To use the toString() method in a scoped application, use the
corresponding scoped method: [toString()](https://servicenow-prod.fluidtopics.net/L4AncQ5ugulI~OI8fgJ_AQ#r_ScopedGlideDateTimeToString "Gets the date and time value stored by the GlideDateTime object in the internal format, yyyy-MM-dd HH:mm:ss, and the system time zone, UTC by default. This method is equivalent to getValue().").

