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

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideDate - Scoped

# GlideDate - Scoped {#ariaid-title1}

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

The scoped GlideDate class provides methods for performing
operations on GlideDate objects, such as instantiating GlideDate objects or working with
GlideDate fields.

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/RgXT711o4n9v_sJ0uKmMsA#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.").

See also [GlideDateTime - Scoped](https://servicenow-prod.fluidtopics.net/xOhnNqU1cKMjoQSfmtxVCw#c_GlideDateTimeScoped "The scoped GlideDateTime class provides methods for performing operations on GlideDateTime objects.").

## Scoped GlideDate - GlideDate() {#ariaid-title2}

Creates a GlideDate object with the current date time.
{#r_ScopedGlideDateGlideDate__table_vy2_525_jq__entry__3}

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

{#r_ScopedGlideDateGlideDate__table_vy2_525_jq}  

    //Today's date is April 21, 2021
    var gd = new GlideDate();
    gs.info(gd.getValue());

Output:

    2021-04-21

## Scoped GlideDate - getByFormat(String format) {#ariaid-title3}

Gets the date in the specified date format.
{#r_ScopedGlideDateGetByFormat_String__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| format | String | Desired date format using Java [SimpleDateFormat](https://docs.oracle.com/javase/10/docs/api/java/text/SimpleDateFormat.html). For example, `"dd-MM-yyyy"` to get the day, month, and year, or `"EEEE"` to get the day of the week. |
[Table 2. Parameters]

{#r_ScopedGlideDateGetByFormat_String__table_vy2_525_jq} {#r_ScopedGlideDateGetByFormat_String__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Date value for the GlideDate object in the specified format. |
[Table 3. Returns]

{#r_ScopedGlideDateGetByFormat_String__table_qpt_3f5_jq}  

    var gd = new GlideDate(); 
    gd.setValue('2021-04-21');
    gs.info(gd.getByFormat("dd-MM-yyyy"));

Output:

    21-04-2021

## Scoped GlideDate - getDayOfMonthNoTZ() {#ariaid-title4}

Gets the day of the month stored by the GlideDate object, expressed in the UTC time
zone.
{#r_SGD-getDayOfMonthNoTZ__table_gdd_z5q_yv__entry__3}

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

{#r_SGD-getDayOfMonthNoTZ__table_gdd_z5q_yv} {#r_SGD-getDayOfMonthNoTZ__table_hdd_z5q_yv__entry__2}

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

{#r_SGD-getDayOfMonthNoTZ__table_hdd_z5q_yv}  

    //Today's date is 2016-05-13 
    var gd =new GlideDate();
    gs.info(gd.getDayOfMonthNoTZ());

Output:

    13

## Scoped GlideDate - getDisplayValue() {#ariaid-title5}

Gets the date and time field value in the UTC time zone.
See also: [getDisplayValueInternal()](https://servicenow-prod.fluidtopics.net/bYyEJu7Q1dOuTUxs_Iquuw#r_ScopedGlideDateGetDisplayValueInternal "Gets the date in the internal format (yyyy-MM-dd) and current user's timezone.")
{#r_ScopedGlideDateGetDisplayValue__table_vy2_535_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| none |   |   |
[Table 6. Parameters]

{#r_ScopedGlideDateGetDisplayValue__table_vy2_535_jq} {#r_ScopedGlideDateGetDisplayValue__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Date value for the GlideDate object in the UTC time zone. |
[Table 7. Returns]

{#r_ScopedGlideDateGetDisplayValue__table_qpt_3f5_jq}  

    var gd = new GlideDate(); 
    gd.setValue('2025-04-21');
    gs.info(gd.getDisplayValue());

Output:

    2025-04-21

## Scoped GlideDate - getDisplayValueInternal() {#ariaid-title6}

Gets the date in the internal format (yyyy-MM-dd) and current user's timezone.
See also [getDisplayValue()](https://servicenow-prod.fluidtopics.net/bYyEJu7Q1dOuTUxs_Iquuw#r_ScopedGlideDateGetDisplayValue "Gets the date and time field value in the UTC time zone.")
{#r_ScopedGlideDateGetDisplayValueInternal__table_vy2_535_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| none |   |   |
[Table 8. Parameters]

{#r_ScopedGlideDateGetDisplayValueInternal__table_vy2_535_jq} {#r_ScopedGlideDateGetDisplayValueInternal__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | Date value for the GlideDate object in the current user's time zone. Format: yyyy-MM-dd |
[Table 9. Returns]

{#r_ScopedGlideDateGetDisplayValueInternal__table_qpt_3f5_jq}  

    var gd = new GlideDate(); 
    gs.info(gd.getDisplayValueInternal());

Output:

    2021-04-21

## Scoped GlideDate - getDisplayValueLang(String style, String language) {#ariaid-title7}

Returns the date value in the user's locale according to a specified language and date
style.
{#r_SGD-getDisplayValueLang_S_S__id_a2q_p5w_dwb__entry__3}

| Name | Type | Description |
|-|-|-|
| style | String | 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 defaults to `medium`. 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/). |
[Table 10. Parameters]

{#r_SGD-getDisplayValueLang_S_S__id_a2q_p5w_dwb} {#r_SGD-getDisplayValueLang_S_S__id_wwn_q5w_dwb__entry__2}

| Type | Description |
|-|-|
| String | Date in the style and language specified according to the locale of the current user. |
[Table 11. Returns]

{#r_SGD-getDisplayValueLang_S_S__id_wwn_q5w_dwb}  
The following example returns the date of the user's locale in various languages and
styles.

    var gd = new GlideDate(); // This will fetch the current date


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

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

Output:


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

## Scoped GlideDate - getMonthNoTZ() {#ariaid-title8}

Gets the month stored by the GlideDate object, expressed in the UTC time zone.
{#r_SGD-getMonthNoTZ__table_az1_3wq_yv__entry__3}

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

{#r_SGD-getMonthNoTZ__table_az1_3wq_yv} {#r_SGD-getMonthNoTZ__table_bz1_3wq_yv__entry__2}

| Type | Description |
|-|-|
| Number | The numerical value of the month from 1 to 12. |
[Table 13. Returns]

{#r_SGD-getMonthNoTZ__table_bz1_3wq_yv}  

    //Today's date is 2016-05-13
    var gd =new GlideDate();
    gs.info(gd.getMonthNoTZ());

Output:

    5

## Scoped GlideDate - getValue() {#ariaid-title9}

Gets the date in the internal format (yyyy-MM-dd) and the system time zone (UTC by
default).
{#r_ScopedGlideDateGetValue__table_vy2_535_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| none |   |   |
[Table 14. Parameters]

{#r_ScopedGlideDateGetValue__table_vy2_535_jq} {#r_ScopedGlideDateGetValue__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| String | The date value for the GlideDate object in the system time zone. Format: yyyy-MM-dd |
[Table 15. Returns]

{#r_ScopedGlideDateGetValue__table_qpt_3f5_jq}  

    var gd = new GlideDate();
    gd.setValue('2021-04-21');
    gs.info(gd.getValue());

Output:

    2021-04-21

## Scoped GlideDate - getYearNoTZ() {#ariaid-title10}

Gets the year stored by the GlideDate object, expressed in the UTC time zone.
{#r_SGD-getYearNoTZ__table_pnp_hxq_yv__entry__3}

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

{#r_SGD-getYearNoTZ__table_pnp_hxq_yv} {#r_SGD-getYearNoTZ__table_qnp_hxq_yv__entry__2}

| Type | Description |
|-|-|
| Number | The numerical value of the year. |
[Table 17. Returns]

{#r_SGD-getYearNoTZ__table_qnp_hxq_yv}  

    //Today's date is 2016-05-13
    var gd =new GlideDate();
    gs.info(gd.getYearNoTZ());

Output:

    2016

## Scoped GlideDate - setDisplayValue(String asDisplayed) {#ariaid-title11}

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

| Name | Type | Description |
|-|-|-|
| asDisplayed | String | Date in the current user's display format and time zone. Format: Must be formatted using the current user's preferred display format, such as yyyy-MM-dd. |
[Table 18. Parameters]

{#r_ScopedGlideDateSetDisplayValue_String__table_vy2_525_jq} {#r_ScopedGlideDateSetDisplayValue_String__table_qpt_3f5_jq1__entry__2}

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

{#r_ScopedGlideDateSetDisplayValue_String__table_qpt_3f5_jq1}  

    var gd = new GlideDate();
    gd.setDisplayValue("2011-01-01");
    gs.info(gd.getValue());

Output:

    2011-01-01

## Scoped GlideDate - setDisplayValueLang(String date, String style) {#ariaid-title12}

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

| Name | Type | Description |
|-|-|-|
| date | String | Date 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, October 25, 2022 or 25.10.2022 are accepted values. |
| style | String | 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 defaults to `medium`. Accepted values are not case sensitive. |
[Table 20. Parameters]

{#r_SGD-setDisplayValueLang_S_S__id_m14_55w_dwb} {#r_SGD-setDisplayValueLang_S_S__id_xh1_v5w_dwb__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 21. Returns]

{#r_SGD-setDisplayValueLang_S_S__id_xh1_v5w_dwb}  
The following example shows how you can set the current date of the user's locale to 'full'
style using setDisplayValueLang().

    glideDate.setDisplayValueLang("2/3/2023", "short");


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

Output:

    date: 2023-02-03
    date: Friday, February 3, 2023

## Scoped GlideDate - setDisplayValueLang(String date, String style, String language) {#ariaid-title13}

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

| Name | Type | Description |
|-|-|-|
| date | String | Date 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, October 25, 2022 or 25.10.2022 are accepted values. |
| style | String | 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 defaults to `medium`. 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/). |
[Table 22. Parameters]

{#r_SGD-setDisplayValueLang_S_S_S__id_kns_w5w_dwb} {#r_SGD-setDisplayValueLang_S_S_S__id_j5m_x5w_dwb__entry__2}

| Type | Description |
|-|-|
| Void |   |
[Table 23. Returns]

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

    var glideDateFR = new GlideDate(); 

    glideDateUS.setDisplayValueLang("2/3/202", "short", "en-US" );
    glideDateFR.setDisplayValueLang("2/3/2023", "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
    en-US date: Friday, February 3, 2023
    fr-FR date: 2023-03-02
    fr-FR date: Thursday, March 2, 2023

## Scoped GlideDate - setValue(String o) {#ariaid-title14}

Sets the date of the current GlideDate object in internal format (yyyy-MM-dd) and the
system time zone (UTC by default).
{#r_ScopedGlideDateSetValue_String__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| o | String | Date and time to set in the current GlideDate object. Format: yyyy-MM-dd |
[Table 24. Parameters]

{#r_ScopedGlideDateSetValue_String__table_vy2_525_jq} {#r_ScopedGlideDateSetValue_String__table_qpt_3f5_jq1__entry__2}

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

{#r_ScopedGlideDateSetValue_String__table_qpt_3f5_jq1}  

    var gd = new GlideDate(); 
    gd.setValue('2015-01-01');
    gs.info(gd.getValue());

Output:

    2015-01-01

## Scoped GlideDate - subtract(GlideDate start, GlideDate end) {#ariaid-title15}

Gets the duration difference between two GlideDate values.
{#r_ScopedGlideDateSubtract_GlideDate_GlideDate__table_vy2_525_jq__entry__3}

| Name | Type | Description |
|-|-|-|
| start | GlideDate | The start value. |
| end | GlideDate | The end value. |
[Table 26. Parameters]

{#r_ScopedGlideDateSubtract_GlideDate_GlideDate__table_vy2_525_jq} {#r_ScopedGlideDateSubtract_GlideDate_GlideDate__table_qpt_3f5_jq__entry__2}

| Type | Description |
|-|-|
| GlideDuration | The duration between the two values. |
[Table 27. Returns]

{#r_ScopedGlideDateSubtract_GlideDate_GlideDate__table_qpt_3f5_jq}  

    var sgd1 = new GlideDate(); 
    sgd1.setDisplayValue('2014-07-18'); 
    var sgd2 = new GlideDate(); 
    sgd2.setDisplayValue('2014-07-19'); 
     
    var duration = GlideDate.subtract(sgd1, sgd2); 
    gs.info(duration.getDisplayValue());

Output:

    1 Day


