{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1003,"path":"api-reference/server-api-reference/c_GlideDateScopedAPI.md","title":"GlideDate - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideDate- Scoped\n\nThe scoped GlideDate class provides methods for performing operations on GlideDate objects, such as instantiating GlideDate objects or working with GlideDate fields.\n\nFor guidance on date time input strings with a list of common format conflicts, refer to [Date and time format guidelines](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/p_GlideServerAPIs.md).\n\nSee also [GlideDateTime - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## Scoped GlideDate - GlideDate\\(\\)\n\nCreates a GlideDate object with the current date time.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n```\n//Today's date is April 21, 2021\nvar gd = new GlideDate();\ngs.info(gd.getValue());\n```\n\nOutput:\n\n```\n2021-04-21\n```\n\n## Scoped GlideDate - getByFormat\\(String format\\)\n\nGets the date in the specified date format.\n\n|Name|Type|Description|\n|----|----|-----------|\n|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.|\n\n|Type|Description|\n|----|-----------|\n|String|Date value for the GlideDate object in the specified format.|\n\n```\nvar gd = new GlideDate(); \ngd.setValue('2021-04-21');\ngs.info(gd.getByFormat(\"dd-MM-yyyy\"));\n```\n\nOutput:\n\n```\n21-04-2021\n```\n\n## Scoped GlideDate - getDayOfMonthNoTZ\\(\\)\n\nGets the day of the month stored by the GlideDate object, expressed in the UTC time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The day of the month in the UTC time zone, from 1 to 31.|\n\n```\n//Today's date is 2016-05-13 \nvar gd =new GlideDate();\ngs.info(gd.getDayOfMonthNoTZ());\n```\n\nOutput:\n\n```\n13\n```\n\n## Scoped GlideDate - getDisplayValue\\(\\)\n\nGets the date and time field value in the UTC time zone.\n\nSee also: [getDisplayValueInternal\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateScopedAPI.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n|Type|Description|\n|----|-----------|\n|String|Date value for the GlideDate object in the UTC time zone.|\n\n```\nvar gd = new GlideDate(); \ngd.setValue('2025-04-21');\ngs.info(gd.getDisplayValue());\n```\n\nOutput:\n\n```\n2025-04-21\n```\n\n## Scoped GlideDate - getDisplayValueEx\\(String style\\)\n\nReturns the date using the current user's timezone and a specified format.\n\n<table id=\"table_tg4_ckc_b3c\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nstyle\n\n</td><td>\n\nString\n\n</td><td>\n\nFormat to use for the date.Valid values \\(case insensitive\\):\n\n-   `short`: M/D/YY or D/M/YY depending on the current user's language. For example, 1/27/26 or 27/1/26.\n-   `medium`: Includes abbreviated month, day, and year. For example, Jan 27, 2026.\n-   `long`: Includes month, day, and year. For example, January 27, 2026.\n-   `full`: Includes day of the week, month, day, and year. For example, Tuesday, January 27, 2026.\n\nThe date is returned in the current user's language. The language determines the order of month and day in the date.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|The date in the specified format.|\n\nThis example returns the date using the current user's timezone and each formatting option.\n\n```\nvar gd = new GlideDate();\ngs.info(gd.getDisplayValueEx(\"short\"));\ngs.info(gd.getDisplayValueEx(\"medium\"));\ngs.info(gd.getDisplayValueEx(\"long\"));\ngs.info(gd.getDisplayValueEx(\"full\"));\n```\n\nOutput:\n\n```\n1/27/26  //short\nJan 27, 2026  //medium\nJanuary 27, 2026  //long\nTuesday, January 27, 2026  //full\n```\n\n## Scoped GlideDate - getDisplayValueInternal\\(\\)\n\nGets the date in the internal format \\(yyyy-MM-dd\\) and current user's timezone.\n\nSee also [Scoped GlideDate - getDisplayValueInternal\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateScopedAPI.md)\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n<table id=\"table_qpt_3f5_jq\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nDate value for the GlideDate object in the current user's time zone. Format: yyyy-MM-dd\n\n</td></tr></tbody>\n</table>```\nvar gd = new GlideDate(); \ngs.info(gd.getDisplayValueInternal());\n```\n\nOutput:\n\n```\n2021-04-21\n```\n\n## Scoped GlideDate - getDisplayValueLang\\(String style, String language\\)\n\nReturns the date value in the user's locale according to a specified language and date style.\n\n<table id=\"id_a2q_p5w_dwb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nstyle\n\n</td><td>\n\nString\n\n</td><td>\n\nDate format. Valid values:\n\n-   full: returns the date in the format of &lt;weekday, month, day, and year&gt; according to the user's locale \\(for example, Monday, October 24, 2022\\).\n-   long: returns the date in the format of &lt;month, day, and year&gt; according to the user's locale \\(for example, October 24, 2022\\).\n-   medium: similar to **long** but returns the date with an abbreviated month \\(for example, Oct 24, 2022\\).\n-   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\\).\n\n If any other value is passed the API defaults to `medium`. Accepted values are not case sensitive.\n\n</td></tr><tr><td>\n\nlanguage\n\n</td><td>\n\nString\n\n</td><td>\n\nReturns 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/).\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|Date in the style and language specified according to the locale of the current user.|\n\nThe following example returns the date of the user's locale in various languages and styles.\n\n```\nvar gd = new GlideDate(); // This will fetch the current date\n\n\ngs.info('date: ' + gd.getDisplayValue());\n\ngs.info('date: ' + gd.getDisplayValueLang(\"full\", \"fr\"));\ngs.info('date: ' + gd.getDisplayValueLang(\"long\", \"en-GB\"));\ngs.info('date: ' + gd.getDisplayValueLang(\"medium\", \"de\"));\ngs.info('date: ' + gd.getDisplayValueLang(\"short\", \"es-MX\"));\n```\n\nOutput:\n\n```\n\ndate: 2023-01-18\ndate: mercredi 18 janvier 2023\ndate: 18 January 2023\ndate: 18.01.2023\ndate: 18/01/23\n```\n\n## Scoped GlideDate - getMonthNoTZ\\(\\)\n\nGets the month stored by the GlideDate object, expressed in the UTC time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The numerical value of the month from 1 to 12.|\n\n```\n//Today's date is 2016-05-13\nvar gd =new GlideDate();\ngs.info(gd.getMonthNoTZ());\n```\n\nOutput:\n\n```\n5\n```\n\n## Scoped GlideDate - getValue\\(\\)\n\nGets the date in the internal format \\(yyyy-MM-dd\\) and the system time zone \\(UTC by default\\).\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n<table id=\"table_qpt_3f5_jq\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nString\n\n</td><td>\n\nThe date value for the GlideDate object in the system time zone. Format: yyyy-MM-dd\n\n</td></tr></tbody>\n</table>```\nvar gd = new GlideDate();\ngd.setValue('2021-04-21');\ngs.info(gd.getValue());\n```\n\nOutput:\n\n```\n2021-04-21\n```\n\n## Scoped GlideDate - getYearNoTZ\\(\\)\n\nGets the year stored by the GlideDate object, expressed in the UTC time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The numerical value of the year.|\n\n```\n//Today's date is 2016-05-13\nvar gd =new GlideDate();\ngs.info(gd.getYearNoTZ());\n```\n\nOutput:\n\n```\n2016\n```\n\n## Scoped GlideDate - setDisplayValue\\(String asDisplayed\\)\n\nSets a date value using the current user's display format and time zone.\n\n<table id=\"table_vy2_525_jq\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nasDisplayed\n\n</td><td>\n\nString\n\n</td><td>\n\nDate 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.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gd = new GlideDate();\ngd.setDisplayValue(\"2011-01-01\");\ngs.info(gd.getValue());\n```\n\nOutput:\n\n```\n2011-01-01\n```\n\n## Scoped GlideDate - setDisplayValueEx\\(String date, String style\\)\n\nSets the date using a specified format.\n\n<table id=\"table_zb5_3kc_b3c\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ndate\n\n</td><td>\n\nString\n\n</td><td>\n\nValue to set for the date. The [getDisplayValueEx\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateScopedAPI.md) method returns dates in a valid format, or dates can be formatted as shown below.\n\n-   M/D/YY or D/M/YY depending on the current user's language. For example, 1/27/26 or 27/1/26.\n-   Abbreviated month, day, and year. For example, Jan 27, 2026.\n-   Month, day, and year. For example, January 27, 2026.\n-   Day of the week, month, day, and year. For example, Tuesday, January 27, 2026.\n\nThe current user's language determines the accepted order of month and day in the date. For example, if the current user's language is English `3/21/26` and `March 21, 2026` are valid values while `21/3/26` and ``21 March, 2026`` are not.\n\n</td></tr><tr><td>\n\nstyle\n\n</td><td>\n\nString\n\n</td><td>\n\nFormat to use for the date.You must use the same format as the provided **date** value.\n\nValid values \\(case insensitive\\):\n\n-   `short`: M/D/YY or D/M/YY depending on the current user's language. For example, 1/27/26 or 27/1/26.\n-   `medium`: Abbreviated month, day, and year. For example, Jan 27, 2026.\n-   `long`: Month, day, and year. For example, January 27, 2026.\n-   `full`: Day of the week, month, day, and year. For example, Tuesday, January 27, 2026.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThis example sets the date using a specified format.\n\n```\ngd = new GlideDate();\ngd.setDisplayValueEx(\"Jan 28, 2026\", \"medium\");\ngs.info(gd.getDisplayValueEx(\"full\"));\n```\n\nOutput:\n\n```\nWednesday, January 28, 2026\n```\n\n## Scoped GlideDate - setDisplayValueLang\\(String date, String style\\)\n\nSets a date using a specified style and format according to the current user's locale.\n\n<table id=\"id_m14_55w_dwb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ndate\n\n</td><td>\n\nString\n\n</td><td>\n\nDate 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.\n\n</td></tr><tr><td>\n\nstyle\n\n</td><td>\n\nString\n\n</td><td>\n\nDate format. Valid values:\n\n-   full: returns the date in the format of &lt;weekday, month, day, and year&gt; according to the user's locale \\(for example, Monday, October 24, 2022\\).\n-   long: returns the date in the format of &lt;month, day, and year&gt; according to the user's locale \\(for example, October 24, 2022\\).\n-   medium: similar to **long** but returns the date with an abbreviated month \\(for example, Oct 24, 2022\\).\n-   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\\).\n\n If any other value is passed the API defaults to `medium`. Accepted values are not case sensitive.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\nThe following example shows how you can set the current date of the user's locale to 'full' style using setDisplayValueLang\\(\\).\n\n```\nglideDate.setDisplayValueLang(\"2/3/2023\", \"short\");\n\n\ngs.info('date: ' + glideDate.getDisplayValue());\ngs.info('date: ' + glideDate.getDisplayValueLang(\"full\"));\n```\n\nOutput:\n\n```\ndate: 2023-02-03\ndate: Friday, February 3, 2023\n```\n\n## Scoped GlideDate - setDisplayValueLang\\(String date, String style, String language\\)\n\nSets a date using a specified style, language, and format according to the current user's locale.\n\n<table id=\"id_kns_w5w_dwb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ndate\n\n</td><td>\n\nString\n\n</td><td>\n\nDate 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.\n\n</td></tr><tr><td>\n\nstyle\n\n</td><td>\n\nString\n\n</td><td>\n\nDate format. Valid values:\n\n-   full: returns the date in the format of &lt;weekday, month, day, and year&gt; according to the user's locale \\(for example, Monday, October 24, 2022\\).\n-   long: returns the date in the format of &lt;month, day, and year&gt; according to the user's locale \\(for example, October 24, 2022\\).\n-   medium: similar to **long** but returns the date with an abbreviated month \\(for example, Oct 24, 2022\\).\n-   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\\).\n\n If any other value is passed the API defaults to `medium`. Accepted values are not case sensitive.\n\n</td></tr><tr><td>\n\nlanguage\n\n</td><td>\n\nString\n\n</td><td>\n\nSets 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/).\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|Void| |\n\nThe following example returns the date and time in short and full styles for English and French.\n\n```\nvar glideDateFR = new GlideDate(); \n\nglideDateUS.setDisplayValueLang(\"2/3/202\", \"short\", \"en-US\" );\nglideDateFR.setDisplayValueLang(\"2/3/2023\", \"short\", \"fr-FR\" );\n\ngs.info('en-US date: ' + glideDateUS.getDisplayValue());\ngs.info('en-US date: ' + glideDateUS.getDisplayValueLang(\"full\"));\n\ngs.info('fr-FR date: ' + glideDateFR.getDisplayValue());\ngs.info('fr-FR date: ' + glideDateFR.getDisplayValueLang(\"full\"));\n```\n\nOutput:\n\n```\nen-US date: 2023-02-03\nen-US date: Friday, February 3, 2023\nfr-FR date: 2023-03-02\nfr-FR date: Thursday, March 2, 2023\n```\n\n## Scoped GlideDate - setValue\\(String o\\)\n\nSets the date of the current GlideDate object in internal format \\(yyyy-MM-dd\\) and the system time zone \\(UTC by default\\).\n\n<table id=\"table_vy2_525_jq\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\no\n\n</td><td>\n\nString\n\n</td><td>\n\nDate and time to set in the current GlideDate object.Format: yyyy-MM-dd\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gd = new GlideDate(); \ngd.setValue('2015-01-01');\ngs.info(gd.getValue());\n```\n\nOutput:\n\n```\n2015-01-01\n```\n\n## Scoped GlideDate - subtract\\(GlideDate start, GlideDate end\\)\n\nGets the duration difference between two GlideDate values.\n\n|Name|Type|Description|\n|----|----|-----------|\n|start|GlideDate|The start value.|\n|end|GlideDate|The end value.|\n\n|Type|Description|\n|----|-----------|\n|GlideDuration|The duration between the two values.|\n\n```\nvar sgd1 = new GlideDate(); \nsgd1.setDisplayValue('2014-07-18'); \nvar sgd2 = new GlideDate(); \nsgd2.setDisplayValue('2014-07-19'); \n \nvar duration = GlideDate.subtract(sgd1, sgd2); \ngs.info(duration.getDisplayValue());\n```\n\nOutput:\n\n```\n1 Day\n```\n\n"}}