How to properly use GlideDateTime objects to avoid date formatting errorsIssue <!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } Using string inputs to create GlideDateTime objects can lead to date formatting errors and incorrect time zone interpretations. This article explains the potential issues and shows you how to properly use GlideDateTime objects. The GlideDateTime class provides methods for performing operations on date and time values. You can use these methods to create GlideDateTime objects, perform calculations, format dates, and convert between formats. You can instantiate a GlideDateTime object in two ways: GlideDateTime(String dateTime): use a string like 08-05-2025 11:34:48 GlideDateTime(GlideDateTime gdt): use another GlideDateTime object Note: GlideDateTime objects store date and time values in the GMT time zone. The getDisplayValue() method returns the date and time in the current user's format and time zone. In the following example, the Due date field on the incident records is set to 08-05-2025 11:34:48 (May 08, 2025 11:34:48) When you use a string to create a GlideDateTime object, the date is incorrectly interpreted as August 5, 2025 21:34:48: var gr = new GlideRecord("incident"); if (gr.get("e58861093b45e610378b9d1d16e45afd")) { var due_date = gr.getValue("due_date"); // GlideDateTime Object var due_date_display_value = gr.due_date.getDisplayValue(); // Date String gs.info("Due Date (GMT): " + due_date) gs.info("Due Date (Display Value): " + due_date_display_value + "\n"); var gdt = new GlideDateTime(due_date); var gdt_display_value = new GlideDateTime(due_date_display_value); // Set user session time zone since GlideDateTime object is in GMT var tz = gs.getSession().getTimeZone(); gdt.setTZ(tz); gs.info("Using GlideDateTime Object: " + gdt.getDisplayValueLang("medium")); gs.info("Using Date String: " + gdt_display_value.getDisplayValueLang("medium")); } Output: *** Script: Due Date (GMT): 2025-05-08 01:34:48 *** Script: Due Date (Display Value): 08-05-2025 11:34:48 *** Script: Using GlideDateTime Object: May 8, 2025 11:34:48 *** Script: Using Date String: Aug 5, 2025 21:34:48 Release<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } All supported releases Cause<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } When you pass a date string to create a GlideDateTime object, the system attempts to match it with several formats in a specific order: Internal system formatyyyy-MM-dd HH:mm:ssMM/dd/yyyy HH:mm:ssMM-dd-yyyy HH:mm:ss(Additional formats...) In this example, the string 08-05-2025 11:34:48 doesn't match the internal system format. The system then tries to interpret it using the MM-dd-yyyy HH:mm:ss format, incorrectly treating 05 (May) as the month and 08 as the day, resulting in August 5 instead of May 8. Note: This issue only occurs when the day value is 12 or less, since there can't be more than 12 months in a year. If the day were 13 or higher, the system correctly interprets the date. Since GlideDateTime processes dates in GMT time zone, when you use a display value string (which already includes time zone adjustments) to create a new GlideDateTime object, the time zone offset is applied twice, causing further time discrepancies. Resolution<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } To prevent date interpretation errors and time zone issues: Always use GlideDateTime objects directly rather than string representations.Remember that GlideDateTime objects store values in GMT time zone, so apply time zone conversions appropriately. Related Links<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } Problems with using gs.nowDateTime() or GlideDateTime.getDisplayValue() in a GlideDateTime constructor GlideDateTime object GlideDateTimeGDT object GlideDateTime(String dateTime) GlideDateTime class GlideDateTime(GlideDateTime gdt)