{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1004,"path":"api-reference/server-api-reference/c_GlideDateTimeAPI.md","title":"GlideDateTime - Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# GlideDateTime- Global\n\nThe 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\n## Modify a glide\\_date\\_time field\n\nWhen working with database columns of type glide\\_date\\_time in GlideDateTime methods, you must first convert the field value into a `GlideDateTime` object before performing date and time calculations. A `glide_date_time` field is represented as a GlideElement; calling Glide Element - getGlideObject\\(\\) returns a `GlideDateTime` object that supports date manipulation methods such as `addMonthsUTC()`. See [GlideElement - getGlideObject\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementAPI.md) for more information.\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## 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## GlideDateTime - GlideDateTime\\(String dateTime\\)\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|dateTime|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## GlideDateTime - GlideDateTime\\(GlideDateTime gdt\\)\n\nInstantiates a new GlideDateTime object set to the time of a specified GlideDateTime object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|gdt|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## GlideDateTime - add\\(Number milliseconds\\)\n\nAdds a specified number of milliseconds to the GlideDateTime object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|milliseconds|Number|The number of milliseconds to add|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngs.print(gdt.getNumericValue());\ngdt.add(10);\ngs.print(gdt.getNumericValue());\n```\n\nOutput:\n\n```\n1314777600000\n1314777600010\n```\n\n### Scoped equivalent\n\nTo use the add\\(\\) method in a scoped application, use the corresponding scoped method: [add\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - add\\(GlideTime time\\)\n\nAdds a GlideTime object to the current GlideDateTime object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|time|[GlideTime](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideTimeScopedAPI.md)|GlideTime object whose time value to add to the specified GlideDateTime object.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\nThis example shows how to add 20 seconds to the time set in the gdt GlideDateTime object.\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\nvar gtime1 = new GlideTime();\ngtime1.setValue(\"00:00:20\");\ngdt.add(gtime1);\ngs.print(gdt.toString());\n```\n\nOutput:\n\n```\n2011-08-31 08:00:20\n```\n\n### Scoped equivalent\n\nTo use the add\\(\\) method in a scoped application, use the corresponding scoped method: [add\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - addDays\\(Number days\\)\n\nAdds a specified number of days to the current GlideDateTime object. A negative parameter subtracts days.\n\nThis method isn’t available in scoped applications. You can alternatively use addDaysLocalTime\\(\\) or addDaysUTC\\(\\) in scoped applications.\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|void| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngdt.addDays(-1);\ngs.print(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-08-30\n```\n\n## GlideDateTime - addDaysLocalTime\\(Number days\\)\n\nAdds a specified number of days to the current GlideDateTime object. A negative parameter subtracts days.\n\nThe 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|void| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngdt.addDaysLocalTime(-1);\ngs.print(gdt.getLocalDate());\n```\n\nOutput:\n\n```\n2011-08-30\n```\n\n### Scoped equivalent\n\nTo use the addDaysLocalTime\\(\\) method in a scoped application, use the corresponding scoped method: [addDaysLocalTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - addDaysUTC\\(Number days\\)\n\nAdds a specified number of days to the current GlideDateTime object. A negative parameter subtracts days.\n\nThe 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 value to subtract.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngdt.addDaysUTC(-1);\ngs.print(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-08-30\n```\n\n### Scoped equivalent\n\nTo use the addDaysUTC\\(\\) method in a scoped application, use the corresponding scoped method: [addDaysUTC\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - addSeconds\\(Number seconds\\)\n\nAdds a specified number of seconds to the GlideDateTime object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|seconds|Number|The number of seconds to add|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime(\"2011-12-07 08:00:00\");\ngdt.addSeconds(1000);\ngs.print(gdt.getValue());\n```\n\nOutput:\n\n```\n2011-12-07 08:16:40\n```\n\n### Scoped equivalent\n\nTo use the addSeconds\\(\\) method in a scoped application, use the corresponding scoped method: [addSeconds\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - addWeeks\\(Number weeks\\)\n\nAdds a specified number of weeks to the current GlideDateTime object. A negative parameter subtracts weeks.\n\nUse addWeeksLocalTime\\(\\) and addWeeksUTC\\(\\) instead of this method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|weeks|Number|The number of weeks to add. Use a negative number to subtract.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngdt.addWeeks(-1);\ngs.print(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-08-24\n```\n\n## GlideDateTime - addWeeksLocalTime\\(Number weeks\\)\n\nAdds a specified number of weeks to the current GlideDateTime object. A negative parameter subtracts weeks.\n\nThe 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 number to subtract.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngdt.addWeeksLocalTime(-1);\ngs.print(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-08-24\n```\n\n### Scoped equivalent\n\nTo use the addWeeksLocalTime\\(\\) method in a scoped application, use the corresponding scoped method: [addWeeksLocalTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - addWeeksUTC\\(Number weeks\\)\n\nAdds a specified number of weeks to the current GlideDateTime object. A negative parameter subtracts weeks.\n\nThe 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 number to subtract.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngdt.addWeeksUTC(-1);\ngs.print(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-08-24\n```\n\n### Scoped equivalent\n\nTo use the addWeeksUTC\\(\\) method in a scoped application, use the corresponding scoped method: [addWeeksUTC\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - addMonths\\(Number months\\)\n\nAdds a specified number of months to the current GlideDateTime object. A negative parameter subtracts months.\n\nUse addMonthsLocalTime\\(\\) or addMonthsUTC\\(\\) instead of this method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|months|Number|The number of months to add. Use a negative number to subtract.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngdt.addMonths(2);\ngs.print(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-10-31\n```\n\n## GlideDateTime - addMonthsLocalTime\\(Number months\\)\n\nAdds a specified number of months to the current GlideDateTime object. A negative parameter subtracts months.\n\nThe 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|void| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngdt.addMonthsLocalTime(2);\ngs.print(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-10-31\n```\n\n### Scoped equivalent\n\nTo use the addMonthsLocalTime\\(\\) method in a scoped application, use the corresponding scoped method: [addMonthsLocalTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - addMonthsUTC\\(Number months\\)\n\nAdds a specified number of months to the current GlideDateTime object. A negative parameter subtracts months.\n\nThe 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\nWhen working with database columns of type glide\\_date\\_time, you must first convert the field value into a `GlideDateTime` object before performing date and time calculations. A `glide_date_time` field is represented as a GlideElement. Calling Glide Element - getGlideObject\\(\\) returns a `GlideDateTime` object that supports date manipulation methods. See [GlideElement - getGlideObject\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideElementAPI.md) for more information.\n\n|Name|Type|Description|\n|----|----|-----------|\n|months|Number|The number of months to add. Use a negative number to subtract.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngdt.addMonthsUTC(2);\ngs.print(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-10-31\n```\n\nThe following example shows how to read a DateTime field from a record, add months using UTC time, and write the updated value back to the field.\n\n```\n// Add 3 months (UTC) to a glide_date_time field on the current record\nvar monthsToAdd = 3;\n\n// Convert the glide_date_time field (GlideElement) to a GlideDateTime object\nvar gdt = current.u_renewal_date.getGlideObject();\n\n// Add months using UTC time\ngdt.addMonthsUTC(monthsToAdd);\n\n// Store the updated value back to the field using the internal (UTC) format\ncurrent.u_renewal_date.setValue(gdt.getValue());\n```\n\n### Scoped equivalent\n\nTo use the addMonthsUTC\\(\\) method in a scoped application, use the corresponding scoped method: [addMonthsUTC\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - addYears\\(Number years\\)\n\nAdds a specified number of years to the current GlideDateTime object. A negative parameter subtracts years.\n\nUse addYearsLocalTime\\(\\) or addYearsUTC\\(\\) instead of this method.\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|void| |\n\n```\nvar gdt = new GlideDateTime(\"2010-08-31 08:00:00\");\ngdt.addYears(1);\ngs.print(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-08-31\n```\n\n## GlideDateTime - addYearsLocalTime\\(Number years\\)\n\nAdds a specified number of years to the current GlideDateTime object. A negative parameter subtracts years.\n\nThe 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. To subtract use a negative value.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime(\"2010-08-31 08:00:00\");\ngdt.addYearsLocalTime(1);\ngs.print(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-08-31\n```\n\n### Scoped equivalent\n\nTo use the AddYearsLocalTime\\(\\) method in a scoped application, use the corresponding scoped method: [AddYearsLocalTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - addYearsUTC\\(Number years\\)\n\nAdds a specified number of years to the current GlideDateTime object. A negative parameter subtracts years.\n\nThe 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|void| |\n\n```\nvar gdt = new GlideDateTime(\"2010-08-31 08:00:00\");\ngdt.addYearsUTC(1);\ngs.print(gdt.getDate());\n```\n\nOutput:\n\n```\n2011-08-31\n```\n\n### Scoped equivalent\n\nTo use the addYearsUTC\\(\\) method in a scoped application, use the corresponding scoped method: [addYearsUTC\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - compareTo\\(Object dateTime\\)\n\nCompares two date and time objects to determine whether one occurs before the other or if they are equivalent.\n\n|Name|Type|Description|\n|----|----|-----------|\n|dateTime|Object|Date time in a GlideDateTime object|\n\n<table id=\"table_tc3_rbd_nt\" 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 equivalent\n\nTo use the compareTo\\(\\) method in a scoped application, use the corresponding scoped method: [compareTo\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - equals\\(Object GDT\\)\n\nCompares an object with an existing value for equality.\n\n|Name|Type|Description|\n|----|----|-----------|\n|GDT|Object|The object to compare. Can be a GlideDateTIme object or a valid date time string.|\n\n|Type|Description|\n|----|-----------|\n|Boolean|True if they are equal, false otherwise.|\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 00:00:00\");\ngs.print(gdt.equals(\"2011-09-30 00:12:01\"));\n```\n\nOutput:\n\n```\n false\n```\n\n### Scoped equivalent\n\nTo use the equals\\(\\) method in a scoped application, use the corresponding scoped method: [equals\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - getDate\\(\\)\n\nReturns the date stored by the GlideDateTime object. Expressed in the format yyyy-MM-dd and in the system time zone, UTC by default.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_njv_xq2_nt\" 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 in the system time zone.Format: yyyy-MM-dd, and in the system time zone, UTC by default.\n\n</td></tr></tbody>\n</table>```\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 equivalent\n\nTo use the getDate\\(\\) method in a scoped application, use the corresponding scoped method: [getDate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - getDayOfMonth\\(\\)\n\nGets the current day of the month in the UTC time zone.\n\nDeprecated. Use getDayOfMonthLocalTime\\(\\) and getDayOfMonthUTC\\(\\) instead of this method.\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.print(gdt.getDayOfMonth());\n```\n\nOutput:\n\n```\n2\n```\n\n## 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.print(gdt.getDayOfMonthLocalTime());\n```\n\nOutput:\n\n```\n2\n```\n\n### Scoped equivalent\n\nTo use the getDayOfMonthLocalTime\\(\\) method in a scoped application, use the corresponding scoped method: [getDayOfMonthLocalTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## 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.print(gdt.getDayOfMonthUTC());\n```\n\nOutput:\n\n```\n2\n```\n\n### Scoped equivalent\n\nTo use the getDayOfMonthUTC\\(\\) method in a scoped application, use the corresponding scoped method: [getDayOfMonthUTC\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - getDayOfWeek\\(\\)\n\nRetrieves the day of the week stored by the GlideDateTime object, expressed in the user's time zone.\n\nUse getDayOfWeekLocalTime\\(\\) and getDayOfWeekUTC\\(\\) instead of this method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The day of the week value - Monday = 1, ... Sunday = 7.|\n\n```\nvar gdt = new GlideDateTime(\"2011-12-01 12:00:00\");\ngs.print(gdt.getDayOfWeek());\n```\n\nOutput:\n\n```\n4\n```\n\n## 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 the week value - Monday = 1, ... Sunday = 7|\n\n```\nvar gdt = new GlideDateTime(\"2011-12-01 12:00:00\");\ngs.print(gdt.getDayOfWeekLocalTime());\n```\n\nOutput:\n\n```\n4\n```\n\n### Scoped equivalent\n\nTo use the getDayOfWeekLocalTime\\(\\) method in a scoped application, use the corresponding scoped method: [getDayOfWeekLocalTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - getDayOfWeekUTC\\(\\)\n\nGets 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|The day of the week value - Monday = 1, ... Sunday = 7|\n\n```\nvar gdt = new GlideDateTime(\"2011-12-01 12:00:00\");\ngs.print(gdt.getDayOfWeekUTC());\n```\n\nOutput:\n\n```\n4\n```\n\n### Scoped equivalent\n\nTo use the getDayOfWeekUTC\\(\\) method in a scoped application, use the corresponding scoped method: [getDayOfWeekUTC\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - getDaysInMonth\\(\\)\n\nGets the number of days in the month stored by the GlideDateTime object, expressed in the Java Virtual Machine time zone.\n\nUse getDaysInMonthLocalTime\\(\\) and getDaysInMonthUTC\\(\\) instead of this method.\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 Java Virtual Machine time zone.|\n\n```\nvar gdt = new GlideDateTime(); //December\ngs.print(gdt.getDaysInMonth());\n```\n\nOutput:\n\n```\n31\n```\n\n## 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(); //December\ngs.print(gdt.getDaysInMonthLocalTime());\n```\n\nOutput:\n\n```\n31\n```\n\n### Scoped equivalent\n\nTo use the getDaysInMonthLocalTime\\(\\) method in a scoped application, use the corresponding scoped method: [getDaysInMonthLocalTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## 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(); //December\ngs.print(gdt.getDaysInMonthUTC());\n```\n\nOutput:\n\n```\n31\n```\n\n### Scoped equivalent\n\nTo use the getDaysInMonthUTC\\(\\) method in a scoped application, use the corresponding scoped method: [getDaysInMonthUTC\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - getDisplayValue\\(\\)\n\nGets the date and time value in the current user's display format and time zone.\n\n**Note:** Referring to the GlideDateTime object directly returns the date and time value in the GMT time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|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.|\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngs.info(gdt.getDisplayValue());\n```\n\nOutput:\n\n```\n2011-08-31 01:00:00\n```\n\n### Scoped equivalent\n\nTo use the getDisplayValue\\(\\) method in a scoped application, use the corresponding scoped method: [getDisplayValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - getDisplayValueInternal\\(\\)\n\nReturns 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_pcw_t1d_nt\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nThe date and time values for the GlideDateTime object.Format: yyyy-MM-dd HH:mm:ss in the caller's time zone.\n\n</td></tr></tbody>\n</table>```\n// The passed in date and time is converted to the caller's time zone.\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngs.info(gdt.getDisplayValueInternal());\n```\n\nOutput:\n\n```\n2011-08-31 01:00:00\n```\n\n### Scoped equivalent\n\nTo use the getDisplayValueInternal\\(\\) method in a scoped application, use the corresponding scoped method: [getDisplayValueInternal\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - getDisplayValueLang\\(String style\\)\n\nReturns a date and time value in the current user's locale according to the specified date style.\n\n<table id=\"id_zqf_hvw_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></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 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\"));\ngs.info('date: ' + gdt.getDisplayValueLang(\"long\"));\ngs.info('date: ' + gdt.getDisplayValueLang(\"medium\"));\ngs.info('date: ' + gdt.getDisplayValueLang(\"short\"));\n```\n\nOutput:\n\n```\ndate: 2023-01-18 06:49:02\ndate: Wednesday, January 18, 2023 06:49:02\ndate: January 18, 2023 06:49:02\ndate: Jan 18, 2023 06:49:02\ndate: 1/18/23 06:49:02\n```\n\n## GlideDateTime - getDisplayValueLang\\(String style, String language\\)\n\nReturns a date and time value in the current user's locale according to a specified language and date style.\n\n<table id=\"id_dfb_4vw_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## 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(\"2011-08-31 08:00:00\");\ngs.print(gdt.getDSTOffset());\n```\n\nOutput:\n\n```\n3600000\n```\n\n### Scoped equivalent\n\nTo use the getDSTOffset\\(\\) method in a scoped application, use the corresponding scoped method: [getDSTOffset\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## 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(\"2011-aa-31 aa:00:00\"); //bad\ngs.print(gdt.isValid()); //false\ngs.print(gdt.getErrorMsg()); //reason\n```\n\nOutput:\n\n```\nfalse\nCould not parse DateTime: 2011-aa-31 aa:00:00\n```\n\n### Scoped equivalent\n\nTo use the getErrorMsg\\(\\) method in a scoped application, use the corresponding scoped method: [getErrorMsg\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## 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|Object|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 equivalent\n\nTo use the getInternalFormattedLocalTime\\(\\) method in a scoped application, use the corresponding scoped method: [getInternalFormattedLocalTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - getInternalMidnight\\(Number dayOfTheWeek\\)\n\nReturns a date and time object set to midnight of a specified day using UTC.\n\n|Name|Type|Description|\n|----|----|-----------|\n|dayOfTheWeek|Number|The day of the week for which to return the date/time object.|\n\n|Type|Description|\n|----|-----------|\n|GlideDateTime|A GlideDateTime object set to midnight.|\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngs.print(gdt.getInternalMidnight(2));\n```\n\nOutput:\n\n```\n2011-08-30 00:00:01\n```\n\n## 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|Description|\n|----|-----------|\n|GlideDate|The date in the user's time zone.|\n\nThis example displays the time in the user's time format in the user's timezone.\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngs.print(gdt.getLocalDate());\n```\n\nOutput:\n\n```\n2011-08-31\n```\n\n### Scoped equivalent\n\nTo use the getLocalDate\\(\\) method in a scoped application, use the corresponding scoped method: [getLocalDate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - getLocalTime\\(\\)\n\nGets the time 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(\"2011-08-31 08:00:00\");\ngs.print(gdt.getLocalTime());\n```\n\nOutput:\n\n```\n1970-01-01 01:00:00\n```\n\n### Scoped equivalent\n\nTo use the getLocalTime\\(\\) method in a scoped application, use the corresponding scoped method: [getLocalTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - getMonth\\(\\)\n\nRetrieves the month stored by the GlideDateTime object, expressed in Java Virtual Machine time zone.\n\nUse getMonthLocalTime\\(\\) and getMonthUTC\\(\\) instead of this method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The numerical value of the month, Jan=1, Dec=12.|\n\n```\nvar gdt = new GlideDateTime(); //December\ngs.print(gdt.getMonth());\n```\n\nOutput:\n\n```\n12\n```\n\n## 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, Jan=1, Dec=12.|\n\n```\nvar gdt = new GlideDateTime(); //December\ngs.print(gdt.getMonthLocalTime());\n```\n\nOutput:\n\n```\n12\n```\n\n### Scoped equivalent\n\nTo use the getMonthLocalTime\\(\\) method in a scoped application, use the corresponding scoped method: [getMonthLocalTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## 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, Jan=1, Dec=12.|\n\n```\nvar gdt = new GlideDateTime(); //December\ngs.print(gdt.getMonthUTC());\n```\n\nOutput:\n\n```\n12\n```\n\n### Scoped equivalent\n\nTo use the getMonthUTC\\(\\) method in a scoped application, use the corresponding scoped method: [getMonthUTC\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## 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.print(gdt.getNumericValue());\n```\n\nOutput:\n\n```\n1314777600000\n```\n\n## GlideDateTime - getSpanTime\\(Number dayOfWeek\\)\n\nRetrieves the amount of time elapsed since the midnight of a specified day to the current time.\n\n|Name|Type|Description|\n|----|----|-----------|\n|dayOfWeek|Number|Day of week value from 1 to 7. 1 = Monday, 7=Sunday.|\n\n|Type|Description|\n|----|-----------|\n|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.|\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\"); //Wednesday\nvar dur = new GlideDuration();\n \nvar span = gdt.getSpanTime(1); //how much time since Monday 00:00:00\ndur.setValue(span);\ngs.print(dur.getDisplayValue());\n```\n\nOutput:\n\n```\n2 Days 8 Hours\n```\n\n## GlideDateTime - getTime\\(\\)\n\nGets the Unix duration stamp.\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(\"2011-08-31 08:00:00\");\ngs.print(gdt.getTime());\n```\n\nOutput:\n\n```\n1970-01-01 08:00:00\n```\n\n### Scoped equivalent\n\nTo use the getTime\\(\\) method in a scoped application, use the corresponding scoped method: [getTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## 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 the time zone offset|\n\n```\nvar gdt = new GlideDateTime();\ngdt.getLocalTime(); // PST local time\ngs.print(gdt.getTZOffset());\n```\n\nOutput:\n\n```\n-28800000\n```\n\n### Scoped equivalent\n\nTo use the getTZOffset\\(\\) method in a scoped application, use the corresponding scoped method: [getTZOffset\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - getUserFormattedLocalTime\\(\\)\n\nReturns the object's time in local time zone in the user's format.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Object|The object's time in local time and the user's format.|\n\nThe following code example shows how to call this method.\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 equivalent\n\nTo use the getUserFormattedLocalTime\\(\\) method in a scoped application, use the corresponding scoped method: [getUserFormattedLocalTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - getUserTimeZone\\(\\)\n\nRetrieves the time zone for the current user session.\n\nThis method is equivalent to `gs.getSession().getTimeZone()`.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|TimeZone|TimeZone object for the current user.|\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngs.print(gdt.getUserTimeZone());\n```\n\nOutput:\n\n```\nsun.util.calendar.ZoneInfo[id=\"America/Los_Angeles\",offset=-28800000,dstSavings=3600000,useDaylight=true,transitions=185,\nlastRule=java.util.SimpleTimeZone[id=America/Los_Angeles,offset=-28800000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,\nstartMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,\nendTime=7200000,endTimeMode=0]]\n```\n\n## GlideDateTime - getUTCMidnight\\(Number dayOfTheWeek\\)\n\nRetrieves a GlideDateTime object with the time set to midnight using the UTC time zone.\n\nThis method sets the date of the new GlideDateTime object as the specified day of the week within the week of the original GlideDateTime object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|dayOfTheWeek|Number|The day of the week, from 1 to 7. Monday=1, Sunday=7. Do not enter 0 in this parameter.|\n\n|Type|Description|\n|----|-----------|\n|GlideDateTime|A new GlideDateTime object, set to midnight.|\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\"); // Wednesday, 3rd day of the week.\ngs.print(gdt.getUTCMidnight(5)); //Friday, 5th day of the week.\n```\n\nOutput:\n\n```\n2011-09-02 00:00:00\n```\n\n## 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_psc_gbd_nt\" 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(\"2011-08-31 08:00:00\");\ngs.info(gdt.getValue());\n```\n\nOutput:\n\n```\n2011-08-31 08:00:00\n```\n\n### Scoped equivalent\n\nTo use the getValue\\(\\) method in a scoped application, use the corresponding scoped method: [getValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## 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\");\ngs.print(gdt.getWeekOfYearUTC());\n```\n\nOutput:\n\n```\n49\n```\n\n### Scoped equivalent\n\nTo use the getWeekOfYearLocalTime\\(\\) method in a scoped application, use the corresponding scoped method: [getWeekOfYearLocalTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## 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\");\ngs.print(gdt.getWeekOfYearUTC());\n```\n\nOutput:\n\n```\n49\n```\n\n### Scoped equivalent\n\nTo use the getWeekOfYearUTC\\(\\) method in a scoped application, use the corresponding scoped method: [getWeekOfYearUTC\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - getYear\\(\\)\n\nRetrieves the year stored by the GlideDateTime object, expressed in the Java Virtual Machine time zone.\n\nUse getYearLocalTime\\(\\) and getYearUTC\\(\\) instead of this method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Number|The 4-digit year value in the Java Virtual Machine time zone.|\n\n```\nvar gdt = new GlideDateTime(); //2011\ngs.print(gdt.getYear());\n```\n\nOutput:\n\n```\n2011\n```\n\n## 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|The 4-digit year value in the user's time zone.|\n\n```\nvar gdt = new GlideDateTime(); //2011\ngs.print(gdt.getYearLocalTime());\n```\n\nOutput:\n\n```\n2011\n```\n\n### Scoped equivalent\n\nTo use the getYearLocalTime\\(\\) method in a scoped application, use the corresponding scoped method: [getYearLocalTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - getYearUTC\\(\\)\n\nReturns 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|Four-digit year value in the UTC time zone.|\n\n```\nvar gdt = new GlideDateTime(); //2011\ngs.info(gdt.getYearUTC());\n```\n\nOutput:\n\n```\n2011\n```\n\n### Scoped equivalent\n\nTo use the getYearUTC\\(\\) method in a scoped application, use the corresponding scoped method: [getYearUTC\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## 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's date is set, false otherwise.|\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\ngs.print(gdt.hasDate());\n```\n\nOutput:\n\n```\ntrue\n```\n\n### Scoped equivalent\n\nTo use the hasDate\\(\\) method in a scoped application, use the corresponding scoped method: [hasDate\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - isDST\\(\\)\n\nDetermines if the 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 time, false otherwise.|\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 00:00:00\");\ngs.print(gdt.isDST()); //true\n```\n\nOutput:\n\n```\ntrue\n```\n\n### Scoped equivalent\n\nTo use the isDST\\(\\) method in a scoped application, use the corresponding scoped method: [isDST\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## 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, false otherwise.|\n\n```\nvar gdt = new GlideDateTime(\"2011-aa-31 aa:00:00\"); \ngs.print(gdt.isValid()); //true\ngs.print(gdt.getErrorMsg()); //reason\n```\n\nOutput\n\n```\nInvalid date time: '2011-aa-31 aa:00:00', ignored\n```\n\n### Scoped equivalent\n\nTo use the isValid\\(\\) method in a scoped application, use the corresponding scoped method: [isValid\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - setDayOfMonth\\(Number day\\)\n\nSets the day of the month to a specified value.\n\nUse setDayOfMonthLocalTime\\(day\\) and setDayOfMonthUTC\\(day\\) instead of this method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|day|Number|Day of the month, from 1 to 31.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setDayOfMonth(9);\ngs.print(gdt.getDayOfMonth());\n```\n\nOutput:\n\n```\n9\n```\n\n## 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|void| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setDayOfMonthLocalTime(9);\ngs.print(gdt.getDayOfMonthLocalTime());\n```\n\nOutput:\n\n```\n9\n```\n\n### Scoped equivalent\n\nTo use the setDayOfMonthLocalTime\\(\\) method in a scoped application, use the corresponding scoped method: [setDayOfMonthLocalTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## 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|void| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setDayOfMonthUTC(9);\ngs.print(gdt.getDayOfMonthUTC());\n```\n\nOutput:\n\n```\n9\n```\n\n### Scoped equivalent\n\nTo use the setDayOfMonthUTC\\(\\) method in a scoped application, use the corresponding scoped method: [setDayOfMonthUTC\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## 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|void| |\n\n```\nvar gdt = new GlideDateTime(\"2011-02-02 12:00:00\");\ngdt.setDisplayValue(\"2011-01-01 12:00:00\");\ngs.print(gdt.getValue());\n```\n\nOutput:\n\n```\n2011-01-01 20:00:00\n```\n\n### Scoped equivalent\n\nTo use the setDisplayValue\\(\\) method in a scoped application, use the corresponding scoped method: [setDisplayValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - setDisplayValue\\(String dateTime, 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 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|dateTime|String|The date and time in the current user's time zone.|\n|format|String|The format to use to parse the dateTime parameter.|\n\n|Type|Description|\n|----|-----------|\n|void| |\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\");\ngs.print(gdt.getValue());\n```\n\nOutput:\n\n```\n2011-05-20 19:00:00\n```\n\n### Scoped equivalent\n\nTo use the setDisplayValue\\(\\) method in a scoped application, use the corresponding scoped method: [setDisplayValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - setDisplayValueInternal\\(String dateTime\\)\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|dateTime|String|The date and time in internal format|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime(\"2011-02-02 12:00:00\");\ngdt.setDisplayValueInternal(\"2011-01-01 12:00:00\");\ngs.print(gdt.getValue());\n```\n\nOutput:\n\n```\n2011-01-01 20:00:00\n```\n\n### Scoped equivalent\n\nTo use the setDisplayValueInternal\\(\\) method in a scoped application, use the corresponding scoped method: [setDisplayValueInternal\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - setDisplayValueInternalWithAlternates\\(String dateTime\\)\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\nThis method attempts to parse incomplete date and time values.\n\n|Name|Type|Description|\n|----|----|-----------|\n|dateTime|String|The date and time in internal format.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n## GlideDateTime - setDisplayValueLang\\(String dateTime, String style\\)\n\nSets a date using a specified style and format according to the current user's locale.\n\n<table id=\"id_jjl_xvw_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## 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_zks_2ww_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## GlideDateTime - setGlideDateTime\\(GlideDateTime gDT\\)\n\nSets the date and time of the current object using an existing GlideDateTime object.\n\nThis method is equivalent to instantiating a new object with a GlideDateTime parameter.\n\n|Name|Type|Description|\n|----|----|-----------|\n|gDT|GlideDateTime|A GlideDateTime object|\n\n|Type|Description|\n|----|-----------|\n|void| |\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.print(dt1.getValue());\n```\n\nOutput:\n\n```\n2011-02-02 08:00:00\n```\n\n### Scoped equivalent\n\nTo use the setGlideDateTime\\(\\) method in a scoped application, use the corresponding scoped method: [setGlideDateTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - setInitialValue\\(String dateTime\\)\n\nSets the date and time.\n\nThis method is equivalent to setValue\\(Object\\).\n\n|Name|Type|Description|\n|----|----|-----------|\n|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.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setInitialValue(\"2011-01-01 12:00:00\");\ngs.print(gdt.getValue());\n```\n\nOutput:\n\n```\n2011-01-01 12:00:00\n```\n\n## GlideDateTime - setMonth\\(Number month\\)\n\nSets the month stored by the GlideDateTime object to a specified value using the Java Virtual Machine time zone.\n\nUse setMonthLocalTime\\(\\) or setMonthUTC\\(\\) instead of this method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|month|Number|The month to change to.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setMonth(1);\ngs.print(gdt.getMonth());\n```\n\nOutput:\n\n```\n1\n```\n\n## GlideDateTime - setMonthLocalTime\\(Number month\\)\n\nSets the month stored by the GlideDateTime object to a 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|void| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setMonthLocalTime(1);\ngs.print(gdt.getMonthLocalTime());\n```\n\nOutput:\n\n```\n1\n```\n\n### Scoped equivalent\n\nTo use the setMonthLocalTime\\(\\) method in a scoped application, use the corresponding scoped method: [setMonthLocalTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - setMonthUTC\\(Number month\\)\n\nSets the month stored by the GlideDateTime object to a 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|void| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setMonthUTC(1);\ngs.print(gdt.getMonthUTC());\n```\n\nOutput:\n\n```\n1\n```\n\n### Scoped equivalent\n\nTo use the setMonthUTC\\(\\) method in a scoped application, use the corresponding scoped method: [setMonthUTC\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - setNumericValue\\(Number milliseconds\\)\n\nSets the date and time to the number of milliseconds since January 1, 1970 00:00:00 GMT.\n\n|Name|Type|Description|\n|----|----|-----------|\n|milliseconds|Number|Number of milliseconds|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setNumericValue(1314777600000);\ngs.print(gdt.getValue());\n```\n\nOutput:\n\n```\n2011-08-31 08:00:00\n```\n\n## GlideDateTime - setTZ\\(TimeZone timeZone\\)\n\nSets the time zone of the GlideDateTime object to be the specified time zone.\n\n|Name|Type|Description|\n|----|----|-----------|\n|timeZone|TimeZone|A time zone object|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar tz = gs.getSession().getTimeZone();\nvar gdt = new GlideDateTime(); \ngdt.setTZ(tz);\n```\n\n## GlideDateTime - setValue\\(Object dateTime\\)\n\nSets the date and time of the GlideDateTime object.\n\nThis method is equivalent to setInitialValue\\(\\).\n\n<table id=\"table_yfh_fpc_nt\" 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\nObject\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\\(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.\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\\(g\\) constructor.\n-   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.\n-   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.\n-   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.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|void| |\n\nSet the date and time using a string in yyyy-MM-dd HH:mm:ss format.\n\n```\nvar gdt = new GlideDateTime(\"2011-01-01 12:00:00\");\ngdt.setValue(\"2011-02-02 08:00:00\");\ngs.print(gdt.getValue());\n```\n\nOutput:\n\n```\n2011-02-02 08:00:00\n```\n\nSet the date and time using an existing GlideDateTime object.\n\n```\nvar gdtSource = new GlideDateTime(\"2017-05-23 11:37:41\");\nvar gdtDest = new GlideDateTime();\ngdtDest.setValue(gdtSource);\ngs.print(gdtDest.getValue());\n```\n\nOutput:\n\n```\n2017-05-23 11:37:41\n```\n\nSet the date and time using a number indicating milliseconds past January 1, 1970 00:00:00 UTC.\n\n```\nvar gdt = new GlideDateTime(\"2011-01-01 12:00:00\");\ngdt.setValue(1617634522375);\ngs.print(gdt.getValue());\n```\n\nOutput:\n\n```\n2021-04-05 14:55:22\n```\n\n### Scoped equivalent\n\nTo use the setValue\\(\\) method in a scoped application, use the corresponding scoped method: [setValue\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - setValueUTC\\(String dateTime, String format\\)\n\nSets a date and time value using the UTC 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 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|dateTime|String|The date and time to use.|\n|format|String|The format to use.|\n\n|Type|Description|\n|----|-----------|\n|void| |\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.print(gdt.getValue());\n```\n\nOutput:\n\n```\n2011-02-15 08:00:00\n```\n\n### Scoped equivalent\n\nTo use the setValueUTC\\(\\) method in a scoped application, use the corresponding scoped method: [setValueUTC\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - setYear\\(Number year\\)\n\nSets the year stored by the GlideDateTime object to a specified value using the Java Virtual Machine time zone.\n\nUse setYearLocalTime\\(\\) or setYearUTC\\(\\) instead of this method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|year|Number|The year to change to.|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setYear(2013);\ngs.print(gdt.getYear());\n```\n\nOutput:\n\n```\n2013\n```\n\n## GlideDateTime - setYearLocalTime\\(Number year\\)\n\nSets the year stored by the GlideDateTime object to a 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|void| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setYearLocalTime(2013);\ngs.print(gdt.getYearLocalTime());\n```\n\nOutput:\n\n```\n2013\n```\n\n### Scoped equivalent\n\nTo use the setYearLocalTime\\(\\) method in a scoped application, use the corresponding scoped method: [setYearLocalTime\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - setYearUTC\\(Number year\\)\n\nSets the year stored by the GlideDateTime object to a 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|void| |\n\n```\nvar gdt = new GlideDateTime();\ngdt.setYearUTC(2013);\ngs.print(gdt.getYearUTC());\n```\n\nOutput:\n\n```\n2013\n```\n\n### Scoped equivalent\n\nTo use the setYearUTC\\(\\) method in a scoped application, use the corresponding scoped method: [setYearUTC\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - subtract\\(GlideTime time\\)\n\nSubtracts a specified amount of time.\n\n|Name|Type|Description|\n|----|----|-----------|\n|time|GlideTime|The time to subtract|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime(\"2011-08-31 08:00:00\");\nvar gtime1 = new GlideTime();\ngtime1.setValue(\"00:00:20\");\ngdt.subtract(gtime1);\ngs.print(gdt.getTime());\n```\n\nOutput:\n\n```\n1970-01-01 07:59:40\n```\n\n### Scoped equivalent\n\nTo use the subtract\\(\\) method in a scoped application, use the corresponding scoped method: [subtract\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - subtract\\(Number milliseconds\\)\n\nSubtracts a specified number of milliseconds from the GlideDateTime object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|milliseconds|Number|The number of milliseconds to subtract|\n\n|Type|Description|\n|----|-----------|\n|void| |\n\n```\nvar gdt = new GlideDateTime(\"2011-12-07 08:00:00\");\ngdt.subtract(1000);\ngs.print(gdt.getValue());\n```\n\nOutput:\n\n```\n2011-12-07 07:59:59\n```\n\n### Scoped equivalent\n\nTo use the subtract\\(\\) method in a scoped application, use the corresponding scoped method: [subtract\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## 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); // Difference between gdt1 and gdt2\ngs.info(dur.getDisplayValue());\n```\n\nOutput:\n\n```\n2 Days 23 Hours\n```\n\n### Scoped equivalent\n\nTo use the subtract\\(\\) method in a scoped application, use the corresponding scoped method: [subtract\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n## GlideDateTime - toString\\(\\)\n\nReturns 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.\n\nThis method is equivalent to getValue\\(\\).\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Object|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.print(gdt.toString());\n```\n\nOutput:\n\n```\n2011-08-31 08:00:00\n```\n\n### Scoped equivalent\n\nTo use the toString\\(\\) method in a scoped application, use the corresponding scoped method: [toString\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideDateTimeScoped.md).\n\n"}}