{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1005,"path":"api-reference/server-api-reference/c_GlideDateTimeScoped.md","title":"GlideDateTime - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideDateTime- Scoped\n\nThe scoped GlideDateTime class provides methods for performing operations on GlideDateTime objects.\n\nUse 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.\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\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 GlideDateTime - GlideDateTime\\(\\)\n\nInstantiates a new GlideDateTime object with the current date and time.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\nThis example instantiates a GlideDateTime object.\n\n```\nvar gdt = new GlideDateTime();\ngs.info(gdt);\n```\n\nOutput:\n\n```\n2022-08-08 16:51:44\n```\n\n## Scoped GlideDateTime - GlideDateTime\\(String value\\)\n\nInstantiates a new GlideDateTime object using the passed-in date and time value.\n\nThe 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:\n\n-   yyyy-MM-dd HH:mm:ss\n-   MM/dd/yyyy HH:mm:ss\n-   MM-dd-yyyy HH:mm:ss\n-   MM-dd-yyyy HH:mm\n-   MM-dd-yyyy\n-   MM/dd/yyyy\n-   dd-MM-yyyy HH:mm:ss\n-   dd-MM-yyyy HH.mm.ss\n-   dd-MM-yyyy HH.mm\n-   dd-MM-yy HH.mm.ss\n-   dd/MM/yyyy\n-   dd-MM-yyyy\n-   yyyy-MM-dd HH:mm\n-   yyyy-MM-dd\n-   dd.MM.yyyy HH:mm:ss\n-   dd.MM.yyyy HH.mm.ss\n-   dd.MM.yyyy hh:mm:ss a\n-   dd.MM.yyyy hh.mm.ss a\n-   dd.MM.yyyy\n\n**Note:** The following format is not supported:\n\n-   yyyy-MM-dd'T'HH:mm:ss.SSSZ\n\n|Name|Type|Description|\n|----|----|-----------|\n|value|String|UTC date and time to set in the GlideDateTime object.|\n\nThis example shows how to instantiate a GlideDateTime object using a string.\n\n```\nvar gdt = new GlideDateTime(\"2023-01-01 12:00:00\");\ngs.info(gdt);\n```\n\nOutput:\n\n```\n2023-01-01 12:00:00\n```\n\n## Scoped GlideDateTime - GlideDateTime\\(GlideDateTime g\\)\n\nInstantiates a new GlideDateTime object set to the time of a specified GlideDateTime object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|g|GlideDateTime|Object used to set the time of the new object.|\n\nThis 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.\n\n```\nvar gdt1 = new GlideDateTime(\"2025-01-28 12:00:00\"); // GlideDateTime(String g)\nvar gdt2 = new GlideDateTime(gdt1); // GlideDateTime(GlideDateTime g)\ngs.info(gdt1);\ngs.info(gdt2);\n```\n\nOutput:\n\n```\n2025-01-28 12:00:00\n2025-01-28 12:00:00\n```\n\n## Scoped GlideDateTime - add\\(GlideTime gd\\)\n\nAdds a GlideTime object to the current GlideDateTime object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|gd|GlideTime|GlideTime object whose time value to add to the specified GlideDateTime object.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\nvar gtime1 = new GlideTime();\ngtime1.setValue(\"00:00:20\");\ngdt.add(gtime1);\nvar gtime2 = gdt.getTime();\ngs.info(gtime2.getByFormat('hh:mm:ss'));\n```\n\nOutput:\n\n```\n08:00:20\n```\n\n## Scoped GlideDateTime - add\\(Number milliseconds\\)\n\nAdds the specified number of milliseconds to the current GlideDateTime object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|milliseconds|Number|The number of milliseconds to add.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngs.info(gdt.getNumericValue());\ngdt.add(10);\ngs.info(gdt.getNumericValue());\n```\n\nOutput:\n\n```\n1314777600000 1314777600010\n```\n\n## Scoped GlideDateTime - addDaysLocalTime\\(Number days\\)\n\nAdds 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|days|Number|The number of days to add. Use a negative value to subtract.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngdt.addDaysLocalTime(-1);\ngs.info(gdt.getLocalDate());\n```\n\nOutput:\n\n```\n2011-08-30\n```\n\n## Scoped GlideDateTime - addDaysUTC\\(Number days\\)\n\nAdds 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|days|Number|The number of days to add. Use a negative number to subtract.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngdt.addDaysUTC(-1);\ngs.info(gdt.getDate());\n```\n\nOutput:\n\n```\n 2011-08-30\n```\n\n## Scoped GlideDateTime - addMonthsLocalTime\\(Number months\\)\n\nAdds 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|months|Number|The number of months to add. use a negative value to subtract.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngdt.addMonthsLocalTime(2);\ngs.info(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-10-31\n```\n\n## Scoped GlideDateTime - addMonthsUTC\\(Number months\\)\n\nAdds 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|months|Number|The number of months to add. Use a negative value to subtract.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngdt.addMonthsUTC(2);\ngs.info(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-10-31\n```\n\n## Scoped GlideDateTime - addSeconds\\(Number seconds\\)\n\nAdds the specified number of seconds to the current GlideDateTime object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|seconds|Number|The number of seconds to add.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2011-12-07 08:00:00\");\ngdt.addSeconds(1000);\ngs.info(gdt.getValue());\n```\n\nOutput:\n\n```\n2011-12-07 08:16:40\n```\n\n## Scoped GlideDateTime - addWeeksLocalTime\\(Number weeks\\)\n\nAdds 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|weeks|Number|The number of weeks to add. Use a negative value to subtract.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngdt.addWeeksLocalTime(-1);\ngs.info(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-08-24\n```\n\n## Scoped GlideDateTime - addWeeksUTC\\(Number weeks\\)\n\nAdds 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|weeks|Number|The number of weeks to add. Use a negative value to subtract.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngdt.addWeeksUTC(-1);\ngs.info(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-08-24\n```\n\n## Scoped GlideDateTime - addYearsLocalTime\\(Number years\\)\n\nAdds 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|years|Number|The number of years to add. Use a negative value to subtract.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2010-08-31 08:00:00\");\ngdt.addYearsLocalTime(1);\ngs.info(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-08-31\n```\n\n## Scoped GlideDateTime - addYearsUTC\\(Number years\\)\n\nAdds 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|years|Number|The number of years to add. Use a negative value to subtract.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2010-08-31 08:00:00\");\ngdt.addYearsUTC(1);\ngs.info(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-08-31\n```\n\n## Scoped GlideDateTime - after\\(GlideDateTime gdt\\)\n\nDetermines if the GlideDateTime object's date and time occurs after the specified object's date and time.\n\n|Name|Type|Description|\n|----|----|-----------|\n|gdt|GlideDateTime|Date and time to check against.|\n\n<table id=\"table_pp2_nqq_yv\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the GlideDateTime object's date and time is after the date and time specified by the parameter.Possible values:\n\n-   true: GlideDateTime object date and time is after the specified object's date and time.\n-   false: GlideDateTime object date and time is before or equal to the specified object's date and time.\n\n</td></tr></tbody>\n</table>```\nvar gdt1 = new GlideDateTime(\"2016-05-09 10:11:12\");\nvar gdt2 = new GlideDateTime(\"2017-06-12 15:11:12\");\ngs.info(gdt1.after(gdt2)); \n```\n\nOutput:\n\n```\nFalse\n```\n\n## Scoped GlideDateTime - before\\(GlideDateTime gdt\\)\n\nDetermines if the GlideDateTime object's date and time occurs before the specified GlideDateTime object's date and time.\n\n|Name|Type|Description|\n|----|----|-----------|\n|gdt|GlideDateTime|Date and time to check against.|\n\n<table id=\"table_k5h_vrq_yv\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the GlideDateTime object's date and time is before the date and time specified by the parameter.Possible values:\n\n-   true: GlideDateTime object date and time is before the specified date and time.\n-   false: GlideDateTime object date and time is after or equal to the specified date and time.\n\n</td></tr></tbody>\n</table>```\nvar gdt1 = new GlideDateTime(\"2016-05-09 10:11:12\");\nvar gdt2 = new GlideDateTime(\"2017-06-12 15:11:12\");\ngs.info(gdt1.before(gdt2));  \n```\n\nOutput\n\n```\ntrue\n```\n\n## Scoped GlideDateTime - compareTo\\(Object o\\)\n\nCompares two date and time objects to determine whether they are equivalent or one occurs before or after the other.\n\n|Name|Type|Description|\n|----|----|-----------|\n|o|Object|Date and time object in GlideDateTime format|\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\nNumber\n\n</td><td>\n\n-   0 = Dates are equal\n-   1 = The object's date is after the date specified in the parameter\n-   -1 = The object's date is before the date specified in the parameter\n\n</td></tr></tbody>\n</table>```\nvar initDate = new GlideDateTime(\"2011-08-01 12:00:00\");\nvar compDate1 = new GlideDateTime(\"2011-08-01 12:00:00\");\nvar compDate2 = new GlideDateTime(\"2011-07-31 12:00:00\");\nvar compDate3 = new GlideDateTime(\"2011-08-04 16:00:00\");\n \ngs.info(initDate.compareTo(compDate1)); // Equals (0)\ngs.info(initDate.compareTo(compDate2)); // initDate is after compDate2 (1)\ngs.info(initDate.compareTo(compDate3)); // initDate is before compDate3 (-1)\n```\n\nOutput:\n\n```\n0\n1\n-1\n```\n\n## Scoped GlideDateTime - equals\\(Object dateTime\\)\n\nCompares a datetime with an existing value for equality.\n\n|Name|Type|Description|\n|----|----|-----------|\n|dateTime|GlideDateTime object or String|The datetime to compare.|\n\n|Type|Description|\n|----|-----------|\n|Boolean|Returns true if they are equal; otherwise, false.|\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 00:00:00\");\ngs.info(gdt.equals(\"2011-09-30 00:12:01\"));\n```\n\nOutput:\n\n```\nfalse\n```\n\n## Scoped GlideDateTime - getDate\\(\\)\n\nReturns the date stored by the GlideDateTime object. Expressed in the standard format, yyyy-MM-dd, and in the system time zone, GMT by default.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Object|Date in the system time zone.|\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngs.info(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-08-31\n```\n\n## Scoped GlideDateTime - getDayOfMonthLocalTime\\(\\)\n\nGets the day of the month stored by the GlideDateTime object, expressed in the current user's time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The day of the month in the user's time zone, from 1 to 31.|\n\n```\nvar gdt = new GlideDateTime(\"2011-12-02 12:00:00\");\ngs.info(gdt.getDayOfMonthLocalTime());\n```\n\nOutput:\n\n```\n2\n```\n\n## Scoped GlideDateTime - getDayOfMonthUTC\\(\\)\n\nGets the day of the month stored by the GlideDateTime 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```\nvar gdt = new GlideDateTime(\"2011-12-02 12:00:00\");\ngs.info(gdt.getDayOfMonthUTC());\n```\n\nOutput:\n\n```\n02\n```\n\n## Scoped GlideDateTime - getDayOfWeekLocalTime\\(\\)\n\nGets the day of the week stored by the GlideDateTime object, expressed in the user's time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The day of week value, in the user's time zone, from 1 to 7. Monday equals 1, Sunday equals 7.|\n\n```\nvar gdt = new GlideDateTime(\"2011-12-01 12:00:00\");//Thursday\ngs.info(gdt.getDayOfWeekLocalTime());\n```\n\nOutput:\n\n```\n4\n```\n\n## Scoped GlideDateTime - getDayOfWeekUTC\\(\\)\n\nReturns the day of the week stored by the GlideDateTime object, expressed in the UTC time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|Day of week value from 1 to 7. Monday equals 1, Sunday equals 7.|\n\n```\nvar gdt = new GlideDateTime(\"2011-12-01 12:00:00\"); //Thursday\ngs.info(gdt.getDayOfWeekUTC());\n```\n\nOutput:\n\n```\n4\n```\n\n## Scoped GlideDateTime - getDaysInMonthLocalTime\\(\\)\n\nGets the number of days in the month stored by the GlideDateTime object, expressed in the current user's time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The number of days in the current month in the user's time zone.|\n\n```\nvar gdt = new GlideDateTime(\"2011-12-02 12:00:00\"); //December\ngs.info(gdt.getDaysInMonthLocalTime());\n```\n\nOutput:\n\n```\n30\n```\n\n## Scoped GlideDateTime - getDaysInMonthUTC\\(\\)\n\nGets the number of days in the month stored by the GlideDateTime object, expressed in the UTC time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The number of days in the month stored by the GlideDateTime object, expressed in the UTC time zone.|\n\n```\nvar gdt = new GlideDateTime(\"2011-11-02 12:00:00\"); //November\ngs.info(gdt.getDaysInMonthUTC());\n```\n\nOutput:\n\n```\n30\n```\n\n## Scoped GlideDateTime - getDisplayValue\\(\\)\n\nGets the date and time value in the current user's display format and time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|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.|\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngs.info(gdt.getDisplayValue()); //uses current user session time zone (US/Pacific)\n```\n\nOutput:\n\n```\n2011-08-31 01:00:00\n```\n\n## Scoped GlideDateTime - getDisplayValueInternal\\(\\)\n\nGets the display value in the internal format \\(yyyy-MM-dd HH:mm:ss\\).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The date and time values for the GlideDateTime object in the current user's time zone and the internal date and time format of `yyyy-MM-dd HH:mm:ss`.|\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\"); \ngs.info(gdt.getDisplayValueInternal()); //uses current user session time zone (US/Pacific)\n```\n\nOutput:\n\n```\n2011-08-31 01:00:00\n```\n\n## Scoped GlideDateTime - getDisplayValueLang\\(String style, String language\\)\n\nReturns a date and time value in the current users' locale according to a specified language and date style.\n\n<table id=\"id_wvq_jww_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\nSpecifies the date and time 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 will default to use *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|A string representation of the date in the style specified and in the appropriate format for the locale of the current user.|\n\nThe following example returns the date and time of the user's locale in all language and date styles.\n\n```\nvar gdt = new GlideDateTime(); // This will fetch the current date\n\n\ngs.info('date: ' + gdt.getDisplayValue());\n\ngs.info('date: ' + gdt.getDisplayValueLang(\"full\", \"fr\"));\ngs.info('date: ' + gdt.getDisplayValueLang(\"long\", \"en-GB\"));\ngs.info('date: ' + gdt.getDisplayValueLang(\"medium\", \"de\"));\ngs.info('date: ' + gdt.getDisplayValueLang(\"short\", \"es-MX\"));```\n```\n\nOutput:\n\n```\ndate: 2023-01-18 06:49:02\nmercredi 18 janvier 2023 06:49:02\n18 January 2023 06:49:02\n18.01.2023 06:49:02\n18/01/23 06:49:02\n```\n\n## Scoped GlideDateTime - getDSTOffset\\(\\)\n\nGets the amount of time that daylight saving time is offset.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|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.|\n\n```\nvar gdt = new GlideDateTime(\"2014-08-31 08:00:00\"); \ngs.info(gdt.getDSTOffset()); //uses current user session time zone (US/Pacific)\n```\n\nOutput:\n\n```\n3600000\n```\n\n## Scoped GlideDateTime - getErrorMsg\\(\\)\n\nGets the current error message.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Object|The error message.|\n\n```\nvar gdt = new GlideDateTime(); \ngdt.setDisplayValue(\"2011-aa-01 00:00:00\"); \ngs.info(gdt.getErrorMsg());\n```\n\nOutput:\n\n```\nCould not parse DateTime: 2011-aa-01 00:00:00\n```\n\n## Scoped GlideDateTime - getInternalFormattedLocalTime\\(\\)\n\nReturns the object's time in the local time zone and in the internal format.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The object's time in the local time zone and the internal format.|\n\nThis example displays the time in the system time format of the user's timezone.\n\n```\nvar gdt = new GlideDateTime('2022-10-08 01:00:00');\ngs.info(gdt.getDisplayValue());\ngs.info(gdt.getInternalFormattedLocalTime());\n```\n\nOutput\n\n```\n2022-10-07 06:00:00 PM\n18:00:00\n```\n\n## Scoped GlideDateTime - getLocalDate\\(\\)\n\nGets the date stored by the GlideDateTime object, expressed in the standard format, yyyy-MM-dd, and the current user's time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type| |\n|----|---|\n|GlideDate|The date in the user's time zone.|\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngs.info(gdt.getLocalDate());\n```\n\nOutput:\n\n```\n2011-08-31\n```\n\n## Scoped GlideDateTime - getLocalTime\\(\\)\n\nReturns a GlideTime object that represents the time portion of the GlideDateTime object in the user's time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|GlideTime|The time in the user's time zone.|\n\n```\nvar gdt = new GlideDateTime(\"2014-08-31 08:00:00\");\ngt = gdt.getLocalTime();\ngs.info(\"local time is \" + gt.getByFormat('hh:mm:ss'));\n```\n\nOutput:\n\n```\nlocal time is 01:00:00\n```\n\n## Scoped GlideDateTime - getMonthLocalTime\\(\\)\n\nGets the month stored by the GlideDateTime object, expressed in the current user's time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The numerical value of the month.|\n\n```\nvar gdt = new GlideDateTime(\"2011-11-02 12:00:00\"); //November\ngs.info(gdt.getMonthLocalTime());\n```\n\nOutput:\n\n```\n11\n```\n\n## Scoped GlideDateTime - getMonthUTC\\(\\)\n\nGets the month stored by the GlideDateTime 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.|\n\n```\nvar gdt = new GlideDateTime(\"2011-11-02 12:00:00\"); //November\ngs.info(gdt.getMonthUTC());\n```\n\nOutput:\n\n```\n11\n```\n\n## Scoped GlideDateTime - getNumericValue\\(\\)\n\nGets the number of milliseconds since January 1, 1970, 00:00:00 GMT.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The number of milliseconds since January 1, 1970, 00:00:00 GMT.|\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngs.info(gdt.getNumericValue());\n```\n\nOutput:\n\n```\n1314777600000\n```\n\n## Scoped GlideDateTime - getTime\\(\\)\n\nReturns a GlideTime object that represents the time portion of the GlideDateTime object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|GlideTime|The Unix duration stamp in system format based on GMT time.|\n\n```\nvar gdt = new GlideDateTime(\"2014-08-31 08:00:00\");\ngt = gdt.getTime();\ngs.info(gt.getByFormat('hh:mm:ss'));\n```\n\nOutput:\n\n```\n08:00:00\n```\n\n## Scoped GlideDateTime - getTZOffset\\(\\)\n\nGets the time zone offset in milliseconds.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The number of milliseconds of time zone offset.|\n\n```\nvar gdt = new GlideDateTime();\ngdt.getLocalTime(); // PST local time\ngs.info(gdt.getTZOffset());\n```\n\nOutput:\n\n```\n-25200000\n```\n\n## Scoped GlideDateTime - getUserFormattedLocalTime\\(\\)\n\nReturns the object's time in the local time zone and in the user's format.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The object's time in the local time zone and in the user's format.|\n\nThis example shows the object's time in the local time zone.\n\n```\nvar gdt = new GlideDateTime('2022-10-08 01:00:00');\ngs.info(gdt.getDisplayValue());\ngs.info(gdt.getUserFormattedLocalTime());\n```\n\nOutput:\n\n```\n2022-10-07 06:00:00 PM\n06:00:00 PM\n```\n\n## Scoped GlideDateTime - getValue\\(\\)\n\nReturns 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.\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 and time in the internal format and system time zone.Format: yyyy-MM-dd HH:mm:ss in the UTC time zone.\n\n</td></tr></tbody>\n</table>```\nvar gdt = new GlideDateTime(\"2014-08-31 08:00:00\");\ngs.info(gdt.getValue());\n```\n\nOutput:\n\n```\n2014-08-31 08:00:00\n```\n\n## Scoped GlideDateTime - getWeekOfYearLocalTime\\(\\)\n\nGets the number of the week stored by the GlideDateTime object, expressed in the current user's time zone.\n\nAll 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The number of the current week. The highest week number in a year is either 52 or 53.|\n\n```\nvar gdt = new GlideDateTime(\"2011-12-01 12:00:00\");//49th week, 1st week in december \ngs.info(gdt.getWeekOfYearLocalTime());\n```\n\nOutput:\n\n```\n49\n```\n\n## Scoped GlideDateTime - getWeekOfYearUTC\\(\\)\n\nGets the number of the week stored by the GlideDateTime object, expressed in the UTC time zone.\n\nAll 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The number of the current week in UTC time. The highest week number in a year is either 52 or 53.|\n\n```\nvar gdt = new GlideDateTime(\"2011-12-01 12:00:00\");//49th week, 1st week in December \ngs.info(gdt.getWeekOfYearUTC());\n```\n\nOutput:\n\n```\n49\n```\n\n## Scoped GlideDateTime - getYearLocalTime\\(\\)\n\nGets the year stored by the GlideDateTime object, expressed in the current user's time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|none| | |\n\n|Type|Description|\n|----|-----------|\n|Number|Four-digit year value in the user's time zone.|\n\n```\nvar gdt = new GlideDateTime(\"2011-11-02 12:00:00\");\ngs.info(gdt.getYearLocalTime());\n```\n\nOutput:\n\n```\n2011\n```\n\n## Scoped GlideDateTime - getYearUTC\\(\\)\n\nGets the year stored by the GlideDateTime object, expressed in the UTC time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|4-digit year value in the UTC time zone.|\n\n```\nvar gdt = new GlideDateTime(\"2011-11-02 12:00:00\"); \ngs.info(gdt.getYearUTC());\n```\n\nOutput:\n\n```\n2011\n```\n\n## Scoped GlideDateTime - hasDate\\(\\)\n\nDetermines if an object's date is set.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the object date is set; otherwise, returns false.|\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngs.info(gdt.hasDate());\n```\n\nOutput:\n\n```\ntrue\n```\n\n## Scoped GlideDateTime - isDST\\(\\)\n\nDetermines if an object's time uses a daylight saving offset.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if the time is daylight saving; otherwise, returns false.|\n\n```\nvar gdt = new GlideDateTime(\"2014-08-31 00:00:00\");\ngs.info(gdt.isDST()); //true\n```\n\nOutput:\n\n```\nvar gdt = new GlideDateTime(\"2014-08-31 00:00:00\");\ngs.info(gdt.isDST()); //true\n```\n\n## Scoped GlideDateTime - isValid\\(\\)\n\nDetermines if a value is a valid date and time.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if value is valid; otherwise, returns false.|\n\n```\nvar gdt = new GlideDateTime(\"2011-aa-31 aa:00:00\"); \ngs.info(gdt.isValid()); //true\ngs.info(gdt.getErrorMsg()); //reason\n```\n\nOutput:\n\n```\nfalse\nInvalid date time: '2011-aa-31 aa:00:00', ignored\n```\n\n## Scoped GlideDateTime - onOrAfter\\(GlideDateTime gdt\\)\n\nDetermines if the GlideDateTime object's data and time occurs on or after the specified GlideDateTime object's date and time.\n\n|Name|Type|Description|\n|----|----|-----------|\n|gdt|GlideDateTime|Date and time to check against.|\n\n<table id=\"table_tst_nsq_yv\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the GlideDateTime object's date and time is on or after the date and time specified by the parameter.Possible values:\n\n-   true: GlideDateTime object date and time is on or after the specified object's date and time.\n-   false: GlideDateTime object date and time is before the specified object's date and time.\n\n</td></tr></tbody>\n</table>```\nvar gdt1 = new GlideDateTime(\"2016-05-09 10:11:12\");\nvar gdt2 = new GlideDateTime(\"2017-06-12 15:11:12\");\ngs.info(gdt1.onOrAfter(gdt2));   \n```\n\nOutput\n\n```\nfalse\n```\n\n## Scoped GlideDateTime - onOrBefore\\(GlideDateTime gdt\\)\n\nDetermines if the GlideDateTime object's data and time occurs on or before the specified GlideDateTime object's date and time.\n\n|Name|Type|Description|\n|----|----|-----------|\n|gdt|GlideDateTime|Date and time to check against.|\n\n<table id=\"table_trp_2tq_yv\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the GlideDateTime object's date and time is on or before the date and time specified by the parameter.Possible values:\n\n-   true: GlideDateTime object date and time is on or before the specified object's date and time.\n-   false: GlideDateTime object date and time is after the specified object's date and time.\n\n</td></tr></tbody>\n</table>```\nvar gdt1 = new GlideDateTime(\"2016-05-09 10:11:12\");\nvar gdt2 = new GlideDateTime(\"2017-06-12 15:11:12\");\ngs.info(gdt1.onOrBefore(gdt2));   \n```\n\nOutput\n\n```\ntrue\n```\n\n## Scoped GlideDateTime - setDayOfMonthLocalTime\\(Number day\\)\n\nSets the day of the month to a specified value in the current user's time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|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.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setDayOfMonthLocalTime(9);\ngs.info(gdt.getDayOfMonthLocalTime());\n```\n\nOutput:\n\n```\n9\n```\n\n## Scoped GlideDateTime - setDayOfMonthUTC\\(Number day\\)\n\nSets the day of the month to a specified value in the UTC time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|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.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setDayOfMonthUTC(9);\ngs.info(gdt.getDayOfMonthUTC());\n```\n\nOutput:\n\n```\n9\n```\n\n## Scoped GlideDateTime - setDisplayValue\\(String asDisplayed\\)\n\nSets a date and time value using the current user's display format and time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|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);`.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2014-02-02 12:00:00\");\ngdt.setDisplayValue(\"2014-01-01 12:00:00\");//uses current user session time zone (US/Pacific) \ngs.info(gdt.getValue());\n```\n\nOutput:\n\n```\n2014-01-01 20:00:00\n```\n\n## Scoped GlideDateTime - setDisplayValue\\(String value, String format\\)\n\nSets a date and time value using the current user's time zone and the specified date and time format.\n\nThis method throws a runtime exception if the date and time format used in the **value** 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.\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\nvalue\n\n</td><td>\n\nString\n\n</td><td>\n\nDate and time in the current user's time zone.\n\n</td></tr><tr><td>\n\nformat\n\n</td><td>\n\nString\n\n</td><td>\n\nDate and time format to use to parse the **value** parameter. Use the following values to describe the **value** parameter:\n\n-   dd: Day of the month\n-   MM: Month of the year\n-   yyyy: Year\n-   HH: Hour\n-   mm: Minutes\n-   ss: Seconds\n\n For example: \"dd-MM-yyyy HH:mm:ss\" or \"MM-dd-yyyy HH:mm\".\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2011-02-02 12:00:00\");\ngdt.setDisplayValue(\"20-5-2011 12:00:00\", \"dd-MM-yyyy HH:mm:ss\"); //uses current user session time zone\ngs.info(gdt.getValue());\n```\n\nOutput\n\n```\n\"20-05-2011 12:00:00\"\n```\n\n## Scoped GlideDateTime - setDisplayValueInternal\\(String value\\)\n\nSets a date and time value using the internal format \\(yyyy-MM-dd HH:mm:ss\\) and the current user's time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|value|String|The date and time in internal format.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2014-02-02 12:00:00\");\ngdt.setDisplayValueInternal(\"2014-01-01 12:00:00\"); //uses current user session time zone (US/Pacific)\ngs.info(gdt.getValue());\n```\n\nOutput:\n\n```\n2014-01-01 20:00:00\n```\n\n## Scoped GlideDateTime - setDisplayValueLang\\(String dateTime, String style\\)\n\nSets a date and time using a specified style and format according to the current user's locale.\n\n<table id=\"id_wc2_nww_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\ndateTime\n\n</td><td>\n\nString\n\n</td><td>\n\nDate 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.\n\n</td></tr><tr><td>\n\nstyle\n\n</td><td>\n\nString\n\n</td><td>\n\nSpecifies the date 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 will default to use *medium*. Accepted values are not case sensitive.\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.\n\n```\nvar glideDateFR = new GlideDateTime();\nglideDateFR.setDisplayValueLang(\"2/3/2023 17:27:56\", \"short\");\n\ngs.info('date: ' + glideDateFR.getDisplayValue());\ngs.info('date: ' + glideDateFR.getDisplayValueLang(\"full\"));\n```\n\nOutput:\n\n```\ndate: 2023-02-03 17:27:56\ndate: Friday, February 3, 2023 17:27:56\n```\n\n## Scoped GlideDateTime - setDisplayValueLang\\(String dateTime, String style, String language\\)\n\nSets a date and time using a specified style, language, and format according to the current user's locale.\n\n<table id=\"id_sgm_qww_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\ndateTime\n\n</td><td>\n\nString\n\n</td><td>\n\nDate 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.\n\n</td></tr><tr><td>\n\nstyle\n\n</td><td>\n\nString\n\n</td><td>\n\nSpecifies the date 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 will default to use *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 GlideDateTime(); \n\nglideDateUS.setDisplayValueLang(\"2/3/2023 18:00:00\", \"short\", \"en-US\" );\nglideDateFR.setDisplayValueLang(\"2/3/2023 18:00:00\", \"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 18:00:00\nen-US date: Friday, February 3, 2023 18:00:00\nfr-FR date: 2023-03-02 18:00:00\nfr-FR date: Thursday, March 2, 2023 18:00:00\n```\n\n## Scoped GlideDateTime - setGlideDateTime\\(GlideDateTime g\\)\n\nSets 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|g|GlideDateTime|The object to use for setting the datetime value.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar dt1 = new GlideDateTime(\"2011-01-01 12:00:00\");\nvar dt2 = new GlideDateTime(\"2011-02-02 08:00:00\");\ndt1.setGlideDateTime(dt2);\ngs.info(dt1.getValue());\n```\n\nOutput:\n\n```\n2011-02-02 08:00:00\n```\n\n## Scoped GlideDateTime - setMonthLocalTime\\(Number month\\)\n\nSets the month stored by the GlideDateTime object to the specified value using the current user's time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|month|Number|The month to change to.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setMonthLocalTime(1);\ngs.info(gdt.getMonthLocalTime());\n```\n\nOutput:\n\n```\n1\n```\n\n## Scoped GlideDateTime - setMonthUTC\\(Number month\\)\n\nSets the month stored by the GlideDateTime object to the specified value using the UTC time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|month|Number|The month to change to.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setMonthUTC(1);\ngs.info(gdt.getMonthUTC());\n```\n\nOutput:\n\n```\n1\n```\n\n## Scoped GlideDateTime - setValue\\(String o\\)\n\nSets the date and time of the GlideDateTime object.\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\nThe 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\\(String 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\\(String dt, String format\\) instead.\n-   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\\(GlideDateTime g\\) constructor.\n-   A JavaScript Number. Sets the value of the object using the Number value as milliseconds past January 1, 1970 00:00:00 UTC.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2011-01-01 12:00:00\");\ngdt.setValue(\"2011-02-02 08:00:00\");  // value set =  2011-02-02 08:00:00\ngs.info(gdt.getValue());\n```\n\nOutput:\n\n```\n2011-02-02 08:00:00\n```\n\n## Scoped GlideDateTime - setValueUTC\\(String dt, String format\\)\n\nSets 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|dt|String|The date and time to use.|\n|format|String|The date and time format to use.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2011-01-01 12:00:00\");\ngdt.setValueUTC(\"15-02-2011 08:00:00\", \"dd-MM-yyyy HH:mm:ss\");\ngs.info(gdt.getValue());\n```\n\nOutput:\n\n```\n2011-02-15 08:00:00\n```\n\n## Scoped GlideDateTime - setYearLocalTime\\(Number year\\)\n\nSets the year stored by the GlideDateTime object to the specified value using the current user's time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|year|Number|The year to change to.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setYearLocalTime(2013);\ngs.info(gdt.getYearLocalTime());\n```\n\nOutput:\n\n```\n2013\n```\n\n## Scoped GlideDateTime - setYearUTC\\(Number year\\)\n\nSets the year stored by the GlideDateTime object to the specified value using the UTC time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|year|Number|The year to change to.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setYearUTC(2013);\ngs.info(gdt.getYearUTC());\n```\n\nOutput:\n\n```\n2013\n```\n\n## Scoped GlideDateTime - subtract\\(GlideTime time\\)\n\nSubtracts a specified amount of time from the current GlideDateTime object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|time|GlideTime|The time value to subtract.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\nvar gtime1 = new GlideTime();\ngtime1.setValue(\"00:00:20\");\ngdt.subtract(gtime1);\nvar gtime2 = gdt.getTime();\ngs.info(gtime2.getByFormat('hh:mm:ss'));\n```\n\nOutput:\n\n```\n07:59:40\n```\n\n## Scoped GlideDateTime - subtract\\(Number milliseconds\\)\n\nSubtracts the specified number of milliseconds from the GlideDateTime object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|milliseconds|Number|Number of milliseconds to subtract.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\n```\nvar gdt = new GlideDateTime(\"2011-12-07 08:00:00\");\ngdt.subtract(1000);\ngs.info(gdt.getValue());\n```\n\nOutput:\n\n```\n2011-12-07 07:59:59\n```\n\n## Scoped GlideDateTime - subtract\\(GlideDateTime start, GlideDateTime end\\)\n\nReturns the duration difference between two specified GlideDateTime objects.\n\n|Name|Type|Description|\n|----|----|-----------|\n|Start|GlideDateTime|Start date object.|\n|End|GlideDateTime|End date object.|\n\n|Type|Description|\n|----|-----------|\n|GlideDuration|Duration difference between the two specified dates.|\n\n```\nvar gdt1 = new GlideDateTime(\"2011-08-28 09:00:00\");\nvar gdt2 = new GlideDateTime(\"2011-08-31 08:00:00\");\n \nvar dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2\ngs.info(dur.getDisplayValue());\n```\n\nOutput:\n\n```\n2 Days 23 Hours\n```\n\n## Scoped GlideDateTime - toString\\(\\)\n\nGets 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\\(\\).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type| |\n|----|---|\n|String|The date and time stored by the GlideDateTime object in the system time zone and format.|\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngs.info(gdt.toString());\n```\n\nOutput:\n\n```\n2011-08-31 08:00:00\n```\n\n"}}